Exemplo n.º 1
0
        public static CurrentRunningData updateCurrentRunningData(CurrentRunningState state, PlayerData player)
        {
            CurrentRunningData currentRunning = null;

            if (state.prev_ts != -1 && player.ts != -1)
            {
                double avgSpeed = -1;
                //picoseconds
                var timespan = player.ts - state.prev_ts;
                //distance travelled in mm
                var dist = QueryHelpers.returnDistance(state.prev_pos_x, state.prev_pos_y, player.pos_x, player.pos_y);
                //distnace travelled in km
                var dist_km = dist / 1000000;
                //Average speed in Km/hr
                if (timespan != 0)
                {
                    avgSpeed = (dist / timespan) * 3.6 * 1000000000;
                }
                currentRunning = new CurrentRunningData()
                {
                    player_id = player.player_name,
                    ts_start  = state.prev_ts,
                    ts_stop   = player.ts,
                    distance  = dist_km,
                    speed     = avgSpeed,
                    intensity = QueryHelpers.returnRunningIntensity(avgSpeed)
                };
            }
            state.prev_ts    = player.ts;
            state.prev_pos_x = player.pos_x;
            state.prev_pos_y = player.pos_y;
            return(currentRunning);
        }
Exemplo n.º 2
0
        public static AggregateRunningData updateAggregateRunningData
            (AggregateRunningData seed, CurrentRunningData curValue,
            IList <CurrentRunningData> expiredList, long count)
        {
            double standing_time = seed.standing_time,
                   standing_dist = seed.standing_distance,
                   trot_time     = seed.trot_time,
                   trot_dist     = seed.trot_distance,
                   low_time      = seed.low_time,
                   low_dist      = seed.low_distance,
                   medium_time   = seed.medium_time,
                   medium_dist   = seed.medium_distance,
                   high_time     = seed.high_time,
                   high_dist     = seed.high_distance,
                   sprint_time   = seed.sprint_time,
                   sprint_dist   = seed.sprint_distance;


            //for each expired element, remove its values from previous seed's values
            foreach (var element in expiredList)
            {
                subtractCurrentRunningData(element, ref standing_time, ref standing_dist,
                                           ref trot_time, ref trot_dist, ref low_time, ref low_dist, ref medium_time,
                                           ref medium_dist, ref high_time, ref high_dist, ref sprint_time, ref sprint_dist);
            }


            //add current values to previous seed values
            addCurrentRunningData(curValue, ref standing_time, ref standing_dist,
                                  ref trot_time, ref trot_dist, ref low_time, ref low_dist, ref medium_time,
                                  ref medium_dist, ref high_time, ref high_dist, ref sprint_time, ref sprint_dist);


            return(new AggregateRunningData
            {
                player_id = curValue.player_id,
                ts = curValue.ts_stop,
                standing_time = standing_time,
                standing_distance = standing_dist,
                trot_time = trot_time,
                trot_distance = trot_dist,
                low_time = low_time,
                low_distance = low_dist,
                medium_time = medium_time,
                medium_distance = medium_dist,
                high_time = high_time,
                high_distance = high_dist,
                sprint_time = sprint_time,
                sprint_distance = sprint_dist
            });
        }
Exemplo n.º 3
0
        private static void subtractCurrentRunningData(CurrentRunningData element,
                                                       ref double standing_time, ref double standing_dist,
                                                       ref double trot_time, ref double trot_dist,
                                                       ref double low_time, ref double low_dist,
                                                       ref double medium_time, ref double medium_dist,
                                                       ref double high_time, ref double high_dist,
                                                       ref double sprint_time, ref double sprint_dist)
        {
            switch (element.intensity)
            {
            case Intensity.STOP:
                standing_dist -= element.distance;
                standing_time -=
                    (element.ts_stop - element.ts_start) / MetaData.PICO_TO_MILI;
                break;

            case Intensity.TROT:
                trot_dist -= element.distance;
                trot_time -=
                    (element.ts_stop - element.ts_start) / MetaData.PICO_TO_MILI;
                break;

            case Intensity.LOW:
                low_dist -= element.distance;
                low_time -=
                    (element.ts_stop - element.ts_start) / MetaData.PICO_TO_MILI;
                break;

            case Intensity.MEDIUM:
                medium_dist -= element.distance;
                medium_time -=
                    (element.ts_stop - element.ts_start) / MetaData.PICO_TO_MILI;
                break;

            case Intensity.HIGH:
                high_dist -= element.distance;
                high_time -=
                    (element.ts_stop - element.ts_start) / MetaData.PICO_TO_MILI;
                break;

            case Intensity.SPRINT:
                sprint_dist -= element.distance;
                sprint_time -=
                    (element.ts_stop - element.ts_start) / MetaData.PICO_TO_MILI;
                break;

            default:
                throw new ApplicationException("Intensity value not recognized");
            }
        }
Exemplo n.º 4
0
        public void query1(PlayerData player)
        {
            incrementInputCount();
            CurrentRunningData currentRunning = QueryHelpers.updateCurrentRunningData(currentRunningState, player);

            if (currentRunning != null)
            {
                aggRunning_full = QueryHelpers.updateAggregateRunningData(aggRunning_full, currentRunning, new List <CurrentRunningData> {
                }, 0);
                pt.OutputCount++;
                aggRunning_1min.getUpdate(currentRunning);
                pt.OutputCount++;
                aggRunning_5min.getUpdate(currentRunning);
                pt.OutputCount++;
                aggRunning_20min.getUpdate(currentRunning);
                pt.OutputCount++;
            }
        }
 //This function adds CurrentRunningData element's time/distance
 //fields to aggregateValues based on this element's intensity
 public static void addToAggregateValues(CurrentRunningData element,
     ref double standing_time, ref double standing_dist,
     ref double trot_time, ref double trot_dist,
     ref double low_time, ref double low_dist,
     ref double medium_time, ref double medium_dist,
     ref double high_time, ref double high_dist,
     ref double sprint_time, ref double sprint_dist)
 {
     switch (element.intensity)
     {
         case Intensity.STOP:
             standing_dist += element.distance;
             standing_time +=
                 (element.ts_stop - element.ts_start) * MetaData.PICO_TO_MILI;
             break;
         case Intensity.TROT:
             trot_dist += element.distance;
             trot_time +=
                 (element.ts_stop - element.ts_start) * MetaData.PICO_TO_MILI;
             break;
         case Intensity.LOW:
             low_dist += element.distance;
             low_time +=
                 (element.ts_stop - element.ts_start) * MetaData.PICO_TO_MILI;
             break;
         case Intensity.MEDIUM:
             medium_dist += element.distance;
             medium_time +=
                 (element.ts_stop - element.ts_start) * MetaData.PICO_TO_MILI;
             break;
         case Intensity.HIGH:
             high_dist += element.distance;
             high_time +=
                 (element.ts_stop - element.ts_start) * MetaData.PICO_TO_MILI;
             break;
         case Intensity.SPRINT:
             sprint_dist += element.distance;
             sprint_time +=
                 (element.ts_stop - element.ts_start) * MetaData.PICO_TO_MILI;
             break;
         default:
             throw new ApplicationException("Intensity value not recognized");
     }
 }
        //This function updates the seed value.
        private static Composite aggregatorFunction(Composite seed, CurrentRunningData curValue,
            IList<CurrentRunningData> expiredList, long count)
        {
            //stash away previous seed values since the seed can't be updated in place.
            double standing_time = seed.data.standing_time,
                standing_dist = seed.data.standing_distance,
                trot_time = seed.data.trot_time,
                trot_dist = seed.data.trot_distance,
                low_time = seed.data.low_time,
                low_dist = seed.data.low_distance,
                medium_time = seed.data.medium_time,
                medium_dist = seed.data.medium_distance,
                high_time = seed.data.high_time,
                high_dist = seed.data.high_distance,
                sprint_time = seed.data.sprint_time,
                sprint_dist = seed.data.sprint_distance,
                lessThanSecDist = seed.lessThanSecDist,
                lessThanSecTime = seed.lessThanSecTime;

            //for each expired element, remove its values from previous seed's values
            foreach (var element in expiredList)
            {
                Console.WriteLine("Subtracting expired element values");
                subtractFromAggregateValues(element, ref standing_time, ref standing_dist,
                    ref trot_time, ref trot_dist, ref low_time, ref low_dist, ref medium_time,
                    ref medium_dist, ref high_time, ref high_dist, ref sprint_time, ref sprint_dist);
            }

            //calculate timeInterval for which current intensity was observed.
            var timeInterval =
                (curValue.ts_stop - curValue.ts_start) * MetaData.PICO_TO_MILI;

            //if this time interval is less than a second (1000miliseconds)
            //then current intensity values - dist and time need to be added
            //to next intensity that is observed for more than a second.
            if (timeInterval < 1000)
            {
                Console.WriteLine("{0} intensity observed for less than 1 sec", curValue.intensity);

                //values for currentRunningData must be added to lessThanSecDist and lessThanSecTime
                //so that when next intensity range for > 1sec is observed, these values can be added
                //to that intensity range.
                lessThanSecDist += curValue.distance;
                lessThanSecTime += timeInterval;

                //return updated seed.
                return new Composite
                {
                    toPublish = false,
                    lessThanSecDist=lessThanSecDist,
                    lessThanSecTime=lessThanSecTime,
                    data = new AggregateRunningData
                    {
                        player_id = curValue.player_id,
                        ts = curValue.ts_stop,
                        standing_time = standing_time,
                        standing_distance = standing_dist,
                        trot_time = trot_time,
                        trot_distance = trot_dist,
                        low_time = low_time,
                        low_distance = low_dist,
                        medium_time = medium_time,
                        medium_distance = medium_dist,
                        high_time = high_time,
                        high_distance = high_dist,
                        sprint_time = sprint_time,
                        sprint_distance = sprint_dist
                    }
                };
            }
            else
            {
                //if lessThanSecDist and lessThanSecTime >0 then there were
                //intensities which were observed for less than a second.
                //Their values need to be added to the current intensity bracket.
                if (lessThanSecDist > 0 && lessThanSecTime > 0)
                {
                    curValue.distance += lessThanSecDist;
                    curValue.ts_stop += (long)(lessThanSecTime / MetaData.PICO_TO_MILI);
                    lessThanSecDist = 0; lessThanSecTime = 0;
                }

                //add current values to previous seed values
                addToAggregateValues(curValue, ref standing_time, ref standing_dist,
                    ref trot_time, ref trot_dist, ref low_time, ref low_dist, ref medium_time,
                    ref medium_dist, ref high_time, ref high_dist, ref sprint_time, ref sprint_dist);
                //return updated seed.
                return new Composite
                {
                    toPublish = true,
                    lessThanSecDist=lessThanSecDist,
                    lessThanSecTime=lessThanSecTime,
                    data = new AggregateRunningData
                    {
                        player_id = curValue.player_id,
                        ts = curValue.ts_stop,
                        standing_time = standing_time,
                        standing_distance = standing_dist,
                        trot_time = trot_time,
                        trot_distance = trot_dist,
                        low_time = low_time,
                        low_distance = low_dist,
                        medium_time = medium_time,
                        medium_distance = medium_dist,
                        high_time = high_time,
                        high_distance = high_dist,
                        sprint_time = sprint_time,
                        sprint_distance = sprint_dist
                    }
                };

            }//end of else block
        }
Exemplo n.º 7
0
        //This function updates the seed value.
        private static Composite aggregatorFunction
            (Composite seed, CurrentRunningData curValue,
            IList <CurrentRunningData> expiredList, long count)
        {
            //stash away previous seed values since the seed can't be updated in place.
            double standing_time   = seed.data.standing_time,
                   standing_dist   = seed.data.standing_distance,
                   trot_time       = seed.data.trot_time,
                   trot_dist       = seed.data.trot_distance,
                   low_time        = seed.data.low_time,
                   low_dist        = seed.data.low_distance,
                   medium_time     = seed.data.medium_time,
                   medium_dist     = seed.data.medium_distance,
                   high_time       = seed.data.high_time,
                   high_dist       = seed.data.high_distance,
                   sprint_time     = seed.data.sprint_time,
                   sprint_dist     = seed.data.sprint_distance,
                   lessThanSecDist = seed.lessThanSecDist,
                   lessThanSecTime = seed.lessThanSecTime;

            //for each expired element, remove its values from previous seed's values
            foreach (var element in expiredList)
            {
                Console.WriteLine("Subtracting expired element values");
                subtractFromAggregateValues(element, ref standing_time, ref standing_dist,
                                            ref trot_time, ref trot_dist, ref low_time, ref low_dist, ref medium_time,
                                            ref medium_dist, ref high_time, ref high_dist, ref sprint_time, ref sprint_dist);
            }

            //calculate timeInterval for which current intensity was observed.
            var timeInterval =
                (curValue.ts_stop - curValue.ts_start) * MetaData.PICO_TO_MILI;

            //if this time interval is less than a second (1000miliseconds)
            //then current intensity values - dist and time need to be added
            //to next intensity that is observed for more than a second.
            if (timeInterval < 1000)
            {
                //Console.WriteLine("{0} intensity observed for less than 1 sec", curValue.intensity);

                //values for currentRunningData must be added to lessThanSecDist and lessThanSecTime
                //so that when next intensity range for > 1sec is observed, these values can be added
                //to that intensity range.
                lessThanSecDist += curValue.distance;
                lessThanSecTime += timeInterval;

                //return updated seed.
                return(new Composite
                {
                    toPublish = false,
                    lessThanSecDist = lessThanSecDist,
                    lessThanSecTime = lessThanSecTime,
                    data = new AggregateRunningData
                    {
                        player_id = curValue.player_id,
                        ts = curValue.ts_stop,
                        standing_time = standing_time,
                        standing_distance = standing_dist,
                        trot_time = trot_time,
                        trot_distance = trot_dist,
                        low_time = low_time,
                        low_distance = low_dist,
                        medium_time = medium_time,
                        medium_distance = medium_dist,
                        high_time = high_time,
                        high_distance = high_dist,
                        sprint_time = sprint_time,
                        sprint_distance = sprint_dist
                    }
                });
            }
            else
            {
                //if lessThanSecDist and lessThanSecTime >0 then there were
                //intensities which were observed for less than a second.
                //Their values need to be added to the current intensity bracket.
                if (lessThanSecDist > 0 && lessThanSecTime > 0)
                {
                    curValue.distance += lessThanSecDist;
                    curValue.ts_stop  += (long)(lessThanSecTime / MetaData.PICO_TO_MILI);
                    lessThanSecDist    = 0; lessThanSecTime = 0;
                }

                //add current values to previous seed values
                addToAggregateValues(curValue, ref standing_time, ref standing_dist,
                                     ref trot_time, ref trot_dist, ref low_time, ref low_dist, ref medium_time,
                                     ref medium_dist, ref high_time, ref high_dist, ref sprint_time, ref sprint_dist);
                //return updated seed.
                return(new Composite
                {
                    toPublish = true,
                    lessThanSecDist = lessThanSecDist,
                    lessThanSecTime = lessThanSecTime,
                    data = new AggregateRunningData
                    {
                        player_id = curValue.player_id,
                        ts = curValue.ts_stop,
                        standing_time = standing_time,
                        standing_distance = standing_dist,
                        trot_time = trot_time,
                        trot_distance = trot_dist,
                        low_time = low_time,
                        low_distance = low_dist,
                        medium_time = medium_time,
                        medium_distance = medium_dist,
                        high_time = high_time,
                        high_distance = high_dist,
                        sprint_time = sprint_time,
                        sprint_distance = sprint_dist
                    }
                });
            } //end of else block
        }     //end of aggregatorFunction