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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
        }
Exemple #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();
        }
        protected override bool EnoughSelector(SkiVideoEntity video, string tag)
        {
            double rope;

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

            return(video.RopeLengthM == rope);
        }
 protected override bool TagSelector(TrainingModels.Tag tag, SkiVideoEntity video)
 {
     if (tag == null || video == null)
     {
         return(false);
     }
     else
     {
         return(tag.Name == video.RopeLengthM.ToString());
     }
 }
Exemple #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());
     }
 }
Exemple #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();
        }
Exemple #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);
        }
        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);
        }
Exemple #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);
        }
Exemple #12
0
 private TrainingModels.Tag CreateTag(SkiVideoEntity video, string tagName)
 {
     TrainingModels.Tag tag = trainingApi.CreateTag(ProjectId, tagName);
     tags.Add(tag);
     return(tag);
 }
Exemple #13
0
 protected abstract bool TagSelector(TrainingModels.Tag tag, SkiVideoEntity video);
Exemple #14
0
 protected override bool EnoughSelector(SkiVideoEntity video, string tag)
 {
     return(video.Skier.Trim() == tag);
 }
 protected override string GetTagValue(SkiVideoEntity video)
 {
     return(video.RopeLengthM.ToString());
 }
Exemple #16
0
 public WebVtt(SkiVideoEntity skiVideo)
 {
     _skiVideo = skiVideo;
 }
        public void TestSkiVideoEntity()
        {
            SkiVideoEntity entity = new SkiVideoEntity();

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