Exemplo n.º 1
0
        public Guid?GetSkierTagId(SkiVideoEntity video)
        {
            try
            {
                if (string.IsNullOrEmpty(video.Skier))
                {
                    return(null);
                }

                string skier = video.Skier.Trim();

                var tag = m_tags.Where(t => t.Name == skier).FirstOrDefault();
                if (tag == null)
                {
                    if (HasEnoughOfSkier(skier))
                    {
                        tag = m_trainingApi.CreateTag(m_projectId, skier);
                        m_tags.Add(tag);
                    }
                }

                return(tag.Id);
            }
            catch (Exception e)
            {
                Logger.Log($"Unable to get SkierTag for {video.Skier}\n" + e);
                return(null);
            }
        }
Exemplo n.º 2
0
        private Guid?GetTagId(SkiVideoEntity video, string tagName,
                              Func <TrainingModels.Tag, SkiVideoEntity, bool> tagSelector,
                              Func <SkiVideoEntity, string, bool> enoughSelector)
        {
            // Forgive the ridiculous nature of all the Func<> parameters, but this generalizes this
            // function so that the derived classes can specify their own implementation of what
            // constitutes a tag without repeating itself; i.e. skier, ropeLength, etc...

            var tag = tags.Where(t => tagSelector(t, video)).FirstOrDefault();

            // No tags, see if we have enough data to create one.
            if (tag == null && EnoughForTag(tagName, enoughSelector))
            {
                tag = CreateTag(video, tagName);
            }

            if (tag != null)
            {
                return(tag.Id);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public void AddMetadata(SkiVideoEntity entity, string json)
        {
            string blobName = GetBlobName(entity.Url, entity.RecordedTime);
            string jsonUrl  = UploadMeasurements(blobName, json);

            entity.JsonUrl = jsonUrl;
            AddTableEntity(entity);
            Logger.Log("Uploaded metadata for video:" + entity.Url);
        }
Exemplo n.º 4
0
        public void UpdateMetadata(SkiVideoEntity entity)
        {
            CloudTableClient client = _account.CreateCloudTableClient();
            CloudTable       table  = client.GetTableReference(SKITABLE);
            TableOperation   update = TableOperation.Merge(entity);

            update.Entity.ETag = "*"; // Allow last-writer wins approach.
            Task updateTask = table.ExecuteAsync(update);

            updateTask.Wait();
        }
Exemplo n.º 5
0
        protected override bool EnoughSelector(SkiVideoEntity video, string tag)
        {
            double rope;

            if (!double.TryParse(tag, out rope))
            {
                return(false);
            }

            return(video.RopeLengthM == rope);
        }
Exemplo n.º 6
0
 protected override bool TagSelector(TrainingModels.Tag tag, SkiVideoEntity video)
 {
     if (tag == null || video == null)
     {
         return(false);
     }
     else
     {
         return(tag.Name == video.RopeLengthM.ToString());
     }
 }
Exemplo n.º 7
0
 protected override bool TagSelector(TrainingModels.Tag tag, SkiVideoEntity video)
 {
     if (tag == null || video == null)
     {
         return(false);
     }
     else
     {
         return(tag.Name == video.Skier.Trim());
     }
 }
Exemplo n.º 8
0
        private void AddTableEntity(SkiVideoEntity entity)
        {
            CloudTableClient client     = _account.CreateCloudTableClient();
            CloudTable       table      = client.GetTableReference(SKITABLE);
            TableOperation   insert     = TableOperation.InsertOrReplace(entity);
            Task             createTask = table.CreateIfNotExistsAsync();

            createTask.Wait();
            Task insertTask = table.ExecuteAsync(insert);

            insertTask.Wait();
        }
Exemplo n.º 9
0
        private IList <Guid> GetTagIds(SkiVideoEntity video)
        {
            //
            // Returns a list of Guids, even though there is only 1 item, or return null if none.
            //

            List <Guid> tagIds = null;
            var         tag    = GetTagId(video, GetTagValue(video), TagSelector, EnoughSelector);

            if (tag != null)
            {
                tagIds = new List <Guid>();
                tagIds.Add((Guid)tag);
            }

            return(tagIds);
        }
Exemplo n.º 10
0
        public Guid?GetRopeTagId(SkiVideoEntity video)
        {
            if (video.RopeLengthM == 0)
            {
                return(null);
            }

            string rope = video.RopeLengthM.ToString();

            var tag = m_tags.Where(t => t.Name == rope).FirstOrDefault();

            if (tag == null)
            {
                if (HasEnoughOfRope(video.RopeLengthM))
                {
                    tag = m_trainingApi.CreateTag(m_projectId, rope);
                    m_tags.Add(tag);
                }
            }

            return(tag.Id);
        }
Exemplo n.º 11
0
        public SkiVideoEntity GetSkiVideoEntity(string recordedDate, string mp4Filename)
        {
            // ParitionKey format YYYY-MM-DD
            // RowKey format e.g. GOPR01444.MP4
            SkiVideoEntity entity = null;

            try
            {
                CloudTableClient   client       = _account.CreateCloudTableClient();
                CloudTable         table        = client.GetTableReference(SKITABLE);
                TableOperation     retrieve     = TableOperation.Retrieve <SkiVideoEntity>(recordedDate, mp4Filename);
                Task <TableResult> retrieveTask = table.ExecuteAsync(retrieve);
                retrieveTask.Wait();
                entity = (SkiVideoEntity)retrieveTask.Result.Result;
            }
            catch (Exception e)
            {
                Logger.Log($"Unable to retrieve SkiVideoEntity; ParitionKey {recordedDate}, RowKey {mp4Filename}", e);
            }

            return(entity);
        }
Exemplo n.º 12
0
 private TrainingModels.Tag CreateTag(SkiVideoEntity video, string tagName)
 {
     TrainingModels.Tag tag = trainingApi.CreateTag(ProjectId, tagName);
     tags.Add(tag);
     return(tag);
 }
Exemplo n.º 13
0
 protected abstract bool TagSelector(TrainingModels.Tag tag, SkiVideoEntity video);
Exemplo n.º 14
0
 protected override bool EnoughSelector(SkiVideoEntity video, string tag)
 {
     return(video.Skier.Trim() == tag);
 }
Exemplo n.º 15
0
 protected override string GetTagValue(SkiVideoEntity video)
 {
     return(video.RopeLengthM.ToString());
 }
Exemplo n.º 16
0
 public WebVtt(SkiVideoEntity skiVideo)
 {
     _skiVideo = skiVideo;
 }
Exemplo n.º 17
0
        public void TestSkiVideoEntity()
        {
            SkiVideoEntity entity = new SkiVideoEntity();

            Console.WriteLine(entity.SlalomTrackerVersion);
        }
Exemplo n.º 18
0
 protected abstract bool EnoughSelector(SkiVideoEntity video, string tag);
Exemplo n.º 19
0
 protected abstract string GetTagValue(SkiVideoEntity video);
Exemplo n.º 20
0
 protected override string GetTagValue(SkiVideoEntity video)
 {
     return(video.Skier.Trim());
 }