Пример #1
0
        private static void UpdateSpanTime(NodeTimeSpan span, PhotoInfo info)
        {
            //Console.WriteLine(string.Format("try to update span for {0}. left: {1}, right: {2}. PhotoTakenDate: {3}", span.Node.FormattedAddress, span.LeftDate.ToString("yyyy-MM-dd HH-mm-ss"), span.RightDate.ToString("yyyy-MM-dd HH-mm-ss"), info.PhotoMetadata.TakenDate.ToString("yyyy-MM-dd HH-mm-ss")));
            if (span.LeftDate > info.PhotoMetadata.TakenDate && span.LeftDate.Subtract(info.PhotoMetadata.TakenDate).TotalDays < config.SpanLimitDays)
            {
                span.LeftDate = info.PhotoMetadata.TakenDate;
                //Console.WriteLine(string.Format("after update left span for {0}. left: {1}, right: {2}", span.Node.FormattedAddress, span.LeftDate.ToString("yyyy-MM-dd HH-mm-ss"), span.RightDate.ToString("yyyy-MM-dd HH-mm-ss")));
            }

            if (span.RightDate < info.PhotoMetadata.TakenDate && info.PhotoMetadata.TakenDate.Subtract(span.RightDate).TotalDays < config.SpanLimitDays)
            {
                span.RightDate = info.PhotoMetadata.TakenDate;
                //Console.WriteLine(string.Format("after update right span for {0}. left: {1}, right: {2}", span.Node.FormattedAddress, span.LeftDate.ToString("yyyy-MM-dd HH-mm-ss"), span.RightDate.ToString("yyyy-MM-dd HH-mm-ss")));
            }
        }
Пример #2
0
        private static NodeTimeSpan CacheNodeTimeSpan(Node node, PhotoInfo info)
        {
            if (node.Parent == null)
            {
                var topNode = node;
                //Console.WriteLine(string.Format("########## parent is null ############### try to cache time span {0} for {1}", node.FormattedAddress, info.PhotoMetadata.FilePath));
                if (!nodeTimeSpanCache.ContainsKey(topNode.PlaceId))
                {
                    NodeTimeSpan span = new NodeTimeSpan();
                    span.Node      = topNode;
                    span.LeftDate  = info.PhotoMetadata.TakenDate;
                    span.RightDate = info.PhotoMetadata.TakenDate;

                    nodeTimeSpanCache.Add(topNode.PlaceId, span);
                }

                var topNodeSpan = nodeTimeSpanCache[topNode.PlaceId];
                UpdateSpanTime(topNodeSpan, info);

                return(topNodeSpan);
            }
            else
            {
                var parentNode = node.Parent;
                //Console.WriteLine(string.Format("########## parent is not null ############### try to cache time span {0} for {1}", node.FormattedAddress, info.PhotoMetadata.FilePath));
                var parentNodeSpan = CacheNodeTimeSpan(parentNode, info);

                if (!parentNodeSpan.Children.ContainsKey(node.PlaceId))
                {
                    NodeTimeSpan span = new NodeTimeSpan();
                    span.Node      = node;
                    span.LeftDate  = info.PhotoMetadata.TakenDate;
                    span.RightDate = info.PhotoMetadata.TakenDate;

                    parentNodeSpan.Children.Add(node.PlaceId, span);
                }

                var childSpan = parentNodeSpan.Children[node.PlaceId];
                UpdateSpanTime(childSpan, info);

                return(parentNodeSpan);
            }
        }
Пример #3
0
        public static Node MatchNodeByTimeSpan(PhotoInfo info, NodeTimeSpan span)
        {
            //Console.WriteLine(string.Format("try to match {0} for {1}", span.Node.FormattedAddress, info.PhotoMetadata.FilePath));
            Node result = null;

            var tolerance = new TimeSpan(0, config.TimeTolerance, 0);
            var leftTime  = span.LeftDate.Subtract(tolerance);
            var rightTime = span.RightDate.Add(tolerance);

            //var leftTime = span.LeftDate;
            //var rightTime = span.RightDate;

            //Console.WriteLine(string.Format("[PhotoHelper]###################### node span details: {0}", JsonConvert.SerializeObject(span)));

            //Console.WriteLine(string.Format("[PhotoHelper]###################### try to append location {0} to {1}. Photo Date {2}, left time: {3}, right time: {4}", span.Node.FormattedAddress, info.PhotoMetadata.FilePath, info.PhotoMetadata.TakenDate.ToString("yyyy-MM-dd HH-mm-ss"), leftTime.ToString("yyyy-MM-dd HH-mm-ss"), rightTime.ToString("yyyy-MM-dd HH-mm-ss")));
            if (info.PhotoMetadata.TakenDate > leftTime && info.PhotoMetadata.TakenDate < rightTime)
            {
                result = span.Node;
                //Console.WriteLine(string.Format("matched {0} for {1}", span.Node.FormattedAddress, info.PhotoMetadata.FilePath));
                if (span.Children.Count > 0)
                {
                    foreach (var childSpan in span.Children)
                    {
                        var childResult = MatchNodeByTimeSpan(info, childSpan.Value);
                        if (childResult != null)
                        {
                            //Console.WriteLine(string.Format("matched child level {0} for {1}", span.Node.FormattedAddress, info.PhotoMetadata.FilePath));
                            result = childResult;
                            break;
                        }
                    }
                }
            }

            return(result);
        }