Пример #1
0
        ///// <summary>
        ///// Gets the average number of items per period.
        ///// </summary>
        ///// <param name="type">The type of average to get.</param>
        ///// <param name="period">The period to calculate.</param>
        ///// <returns>The averages meeting the specified criteria.</returns>
        //public DataTable GetAverage(Enumerators.StatisticsType type, Enumerators.Period period)
        //{
        //    return GetAverage(type, period, (DataFactory)null);
        //}

        ///// <summary>
        ///// Gets the average number of items per period.
        ///// </summary>
        ///// <param name="type">The type of average to get.</param>
        ///// <param name="period">The period to calculate.</param>
        ///// <param name="dataFactory">The data to use for testing.</param>
        ///// <returns>The averages meeting the specified criteria.</returns>
        //public DataTable GetAverage(Enumerators.StatisticsType type, Enumerators.Period period, DataFactory dataFactory)
        //{
        //    DataTable result = null;

        //    DataFactory df = new DataFactory();

        //    if (dataFactory != null)
        //        df = dataFactory;

        //    DataTable temp = null;

        //    List<string> list = ParseSerialIds();

        //    int[] ids = new int[list.Count];

        //    for (int i = 0; i < list.Count; i++)
        //        ids[i] = Convert.ToInt32(list[i]);

        //    if (type == Enumerators.StatisticsType.DataUsage)
        //    {
        //        this.eventPacket = df.GetNewEventPacket();
        //        temp = this.eventPacket.GetEventPackets(ids, this.startDate, this.endDate);
        //    }
        //    else
        //    {
        //        this.gpsData = df.GetNewGpsData();
        //        temp = this.gpsData.GetHits(ids, this.startDate, this.endDate);
        //    }

        //    if (temp != null)
        //    {
        //        result = new DataTable();

        //        result.Columns.Add("SerialId", typeof(int));
        //        result.Columns.Add("Average", typeof(double));

        //        foreach (int i in ids)
        //        {
        //            DataRow[] rows = null;

        //            if (type == Enumerators.StatisticsType.DataUsage)
        //                rows = temp.Select("SerialId = " + i.ToString());
        //            else
        //                rows = temp.Select("lSerial_ID = " + i.ToString());

        //            double average = 0;

        //            try
        //            {
        //                if (type == Enumerators.StatisticsType.DataUsage)
        //                    average = rows.Average(x => x.Field<int>("PacketSize"));
        //                else
        //                    average = rows.Average(x => x.Field<int>("Hits"));

        //                switch (period)
        //                {
        //                    case Enumerators.Period.Week:
        //                        average /= 7;
        //                        break;

        //                    case Enumerators.Period.Month:
        //                        average /= 30;
        //                        break;
        //                }

        //                DataRow row = result.NewRow();

        //                row["SerialId"] = i;
        //                row["Average"] = Math.Round(average, 5);

        //                result.Rows.Add(row);
        //            }
        //            catch (InvalidOperationException)
        //            {
        //                //NOP
        //            }
        //        }
        //    }

        //    return result;
        //}

        ///// <summary>
        ///// Gets the devices that exceed a specified threshold for a period.
        ///// </summary>
        ///// <param name="type">The type of threshold to get.</param>
        ///// <param name="period">The period to calculate.</param>
        ///// <returns>The devices meeting the specified criteria.</returns>
        //public DataTable GetDevicesOverThreshold(Enumerators.StatisticsType type, Enumerators.Period period)
        //{
        //    return GetDevicesOverThreshold(type, period, (DataFactory)null);
        //}

        ///// <summary>
        ///// Gets the devices that exceed a specified threshold for a period.
        ///// </summary>
        ///// <param name="type">The type of threshold to get.</param>
        ///// <param name="period">The period to calculate.</param>
        ///// <param name="dataFactory">The data to use for testing.</param>
        ///// <returns>The devices meeting the specified criteria.</returns>
        //public DataTable GetDevicesOverThreshold(Enumerators.StatisticsType type, Enumerators.Period period, DataFactory dataFactory)
        //{
        //    DataTable result = null;

        //    DataFactory df = new DataFactory();

        //    if (dataFactory != null)
        //        df = dataFactory;

        //    DataTable temp = null;

        //    if (type == Enumerators.StatisticsType.DataUsage)
        //    {
        //        this.eventPacket = df.GetNewEventPacket();
        //        temp = this.eventPacket.GetPacketsByDateRange(this.startDate, this.endDate);
        //    }
        //    else
        //    {
        //        this.gpsData = df.GetNewGpsData();
        //        temp = this.gpsData.GetHitsByDateRange(this.startDate, this.endDate);
        //    }

        //    if (temp != null)
        //    {
        //        result = new DataTable();

        //        DataRow[] rows = new DataRow[temp.Rows.Count];

        //        temp.Rows.CopyTo(rows, 0);

        //        List<DataRow> filter = null;

        //        List<int> ids = null;

        //        try
        //        {
        //            if (period != Enumerators.Period.Day)
        //            {
        //                if (type == Enumerators.StatisticsType.DataUsage)
        //                    ids = (from r in rows
        //                           select r.Field<int>("SerialId")).Distinct().ToList();
        //                else
        //                    ids = (from r in rows
        //                           select r.Field<int>("lSerial_ID")).Distinct().ToList();
        //            }

        //            switch (period)
        //            {
        //                case Enumerators.Period.Day:
        //                    result.Columns.Add("SerialId", typeof(int));
        //                    result.Columns.Add("ReceivedDate", typeof(DateTime));
        //                    result.Columns.Add("Count", typeof(int));

        //                    try
        //                    {
        //                        if (type == Enumerators.StatisticsType.DataUsage && this.dataUsageThreshold > -1)
        //                            filter = rows.Where(x => x.Field<int>("PacketSize") >= this.dataUsageThreshold).ToList<DataRow>();
        //                        else if (this.afltHitThreshold > -1)
        //                            filter = rows.Where(x => x.Field<int>("Hits") >= this.afltHitThreshold).ToList<DataRow>();
        //                    }
        //                    catch (InvalidOperationException)
        //                    {
        //                        //NOP
        //                    }
        //                    break;

        //                case Enumerators.Period.Week:
        //                    result.Columns.Add("SerialId", typeof(int));
        //                    result.Columns.Add("WeeklyCount", typeof(int));

        //                    foreach (int id in ids)
        //                    {
        //                        int sum = 0;

        //                        try
        //                        {
        //                            if (type == Enumerators.StatisticsType.DataUsage)
        //                            {
        //                                sum = (from f in rows
        //                                       where f.Field<int>("SerialId") == id
        //                                       select f.Field<int>("PacketSize")).Sum();

        //                                if (sum >= this.dataUsageThreshold)
        //                                {
        //                                    DataRow row = result.NewRow();
        //                                    row["SerialId"] = id;
        //                                    row["WeeklyCount"] = sum;

        //                                    if (filter == null)
        //                                        filter = new List<DataRow>();

        //                                    filter.Add(row);
        //                                }
        //                            }
        //                            else
        //                            {
        //                                sum = (from f in rows
        //                                       where f.Field<int>("lSerial_ID") == id
        //                                       select f.Field<int>("Hits")).Sum();

        //                                if (sum >= this.afltHitThreshold)
        //                                {
        //                                    DataRow row = result.NewRow();
        //                                    row["SerialId"] = id;
        //                                    row["WeeklyCount"] = sum;

        //                                    if (filter == null)
        //                                        filter = new List<DataRow>();

        //                                    filter.Add(row);
        //                                }
        //                            }
        //                        }
        //                        catch (InvalidOperationException)
        //                        {
        //                            //NOP
        //                        }
        //                    }

        //                    break;

        //                case Enumerators.Period.Month:
        //                    result.Columns.Add("SerialId", typeof(int));
        //                    result.Columns.Add("MonthlyCount", typeof(int));

        //                    foreach (int id in ids)
        //                    {
        //                        int sum = 0;

        //                        try
        //                        {
        //                            if (type == Enumerators.StatisticsType.DataUsage)
        //                            {
        //                                sum = (from f in rows
        //                                       where f.Field<int>("SerialId") == id
        //                                       select f.Field<int>("PacketSize")).Sum();

        //                                if (sum >= this.dataUsageThreshold)
        //                                {
        //                                    DataRow row = result.NewRow();
        //                                    row["SerialId"] = id;
        //                                    row["MonthlyCount"] = sum;

        //                                    if (filter == null)
        //                                        filter = new List<DataRow>();

        //                                    filter.Add(row);
        //                                }
        //                            }
        //                            else
        //                            {
        //                                sum = (from f in rows
        //                                       where f.Field<int>("lSerial_ID") == id
        //                                       select f.Field<int>("Hits")).Sum();

        //                                if (sum >= this.afltHitThreshold)
        //                                {
        //                                    DataRow row = result.NewRow();
        //                                    row["SerialId"] = id;
        //                                    row["MonthlyCount"] = sum;

        //                                    if (filter == null)
        //                                        filter = new List<DataRow>();

        //                                    filter.Add(row);
        //                                }
        //                            }
        //                        }
        //                        catch (InvalidOperationException)
        //                        {
        //                            //NOP
        //                        }
        //                    }
        //                    break;
        //            }
        //        }
        //        catch (InvalidOperationException)
        //        {
        //            //NOP
        //        }

        //        result.Rows.Clear();

        //        if (filter != null)
        //        {
        //            foreach (DataRow dr in filter)
        //            {
        //                result.NewRow();

        //                switch (period)
        //                {
        //                    case Enumerators.Period.Day:
        //                        if (type == Enumerators.StatisticsType.DataUsage)
        //                            result.Rows.Add(dr["SerialId"], dr["ReceivedDate"], dr["PacketSize"]);
        //                        else
        //                            result.Rows.Add(dr["lSerial_ID"], dr["Received"], dr["Hits"]);
        //                        break;

        //                    case Enumerators.Period.Month:
        //                        result.Rows.Add(dr["SerialId"], dr["MonthlyCount"]);
        //                        break;

        //                    case Enumerators.Period.Week:
        //                        result.Rows.Add(dr["SerialId"], dr["WeeklyCount"]);
        //                        break;
        //                }
        //            }
        //        }
        //    }

        //    return result;
        //}

        /// <summary>
        /// Gets the data usage or AFLT hits for the period.
        /// </summary>
        /// <param name="type">The type of count to get.</param>
        /// <returns>The devices meeting the specified criteria.</returns>
        public DataTable GetData(Enumerators.StatisticsType type)
        {
            return(GetData(type, (DataFactory)null));
        }
Пример #2
0
        /// <summary>
        /// Gets the data usage or AFLT hits for the period.
        /// </summary>
        /// <param name="type">The type of count to get.</param>
        /// <param name="dataFactory">The data to use for testing.</param>
        /// <returns>The devices meeting the specified criteria.</returns>
        public DataTable GetData(Enumerators.StatisticsType type, DataFactory dataFactory)
        {
            DataTable result = null;

            DataFactory df = new DataFactory();

            if (dataFactory != null)
            {
                df = dataFactory;
            }

            DataTable temp = null;

            try
            {
                if (type == Enumerators.StatisticsType.DataUsage)
                {
                    this.eventPacket = df.GetNewEventPacket();
                    temp             = this.eventPacket.GetPacketsByDateRange(this.startDate, this.endDate);
                }
                else
                {
                    this.gpsData = df.GetNewGpsData();
                    temp         = this.gpsData.GetHitsByDateRange(this.startDate, this.endDate);
                }

                if (temp != null)
                {
                    result = new DataTable();

                    result.Columns.Add("SerialId", typeof(int));
                    result.Columns.Add("ReceivedDate", typeof(DateTime));
                    result.Columns.Add("Count", typeof(int));

                    DataRow[] rows = new DataRow[temp.Rows.Count];

                    temp.Rows.CopyTo(rows, 0);

                    int            max    = 0;
                    List <DataRow> filter = new List <DataRow>();

                    if (type == Enumerators.StatisticsType.DataUsage)
                    {
                        max = (from r in rows
                               select r.Field <int>("PacketSize")).Max();

                        filter = (from r in rows
                                  where r.Field <int>("PacketSize") == max
                                  select r).ToList();
                    }
                    else
                    {
                        max = (from r in rows
                               select r.Field <int>("Hits")).Max();

                        filter = (from r in rows
                                  where r.Field <int>("Hits") == max
                                  select r).ToList();
                    }

                    foreach (DataRow row in filter)
                    {
                        result.NewRow();

                        if (type == Enumerators.StatisticsType.DataUsage)
                        {
                            result.Rows.Add(row["SerialId"], row["ReceivedDate"], row["PacketSize"]);
                        }
                        else
                        {
                            result.Rows.Add(row["lSerial_ID"], row["Received"], row["Hits"]);
                        }
                    }
                }
            }
            finally
            {
                temp.Dispose();
            }

            return(result);
        }
Пример #3
0
        private List <Window> Calculate(Statistics stats, Enumerators.Period pd, Enumerators.StatisticsType type, bool?average, bool?high, bool?low,
                                        bool?stdDev, bool?threshold)
        {
            List <Window> result = new List <Window>();

            //DataTable highTable = null;
            //DataTable lowTable = null;
            //DataTable thresholdTable = null;
            //double standardDeviation = 0;

            //Enumerators.GraphType graphType = Enumerators.GraphType.Average;

            string title = "AFLT Hits";

            if (type == Enumerators.StatisticsType.DataUsage)
            {
                title = "Cell Data Usage";
            }

            //if (average.HasValue && average.Value)
            //    averageTable = stats.GetAverage(type, pd);

            DataTable data = stats.GetData(type);

            if (data != null)
            {
                data.TableName = title;

                Charts charts = new Charts();



                result.Add(charts);

                //if (data.Rows.Count > 1)
                //    result.Add(new Charts());
                //else
                //    result.Add(new Lists(data));
            }

            //if (high.HasValue && high.Value)
            //    highTable = stats.GetHighest(type);

            //if (highTable != null)
            //{
            //    highTable.TableName = title + "Highest";

            //    graphType = Enumerators.GraphType.Highest;

            //    if (highTable.Rows.Count > 1)
            //        result.Add(new Charts(highTable, graphType));
            //    else
            //        result.Add(new Lists(highTable));
            //}

            //if (low.HasValue && low.Value)
            //    lowTable = stats.GetLowest(type);

            //if (lowTable != null)
            //{
            //    lowTable.TableName = title + "Lowest";

            //    graphType = Enumerators.GraphType.Lowest;

            //    if (lowTable.Rows.Count > 1)
            //        result.Add(new Charts(lowTable, graphType));
            //    else
            //        result.Add(new Lists(lowTable));
            //}

            //Figure out where to put this.

            //if (stdDev.HasValue && stdDev.Value)
            //    standardDeviation = stats.GetStandardDeviation(type, pd);

            //if (threshold.HasValue && threshold.Value)
            //    thresholdTable = stats.GetDevicesOverThreshold(type, pd);

            //if (thresholdTable != null)
            //{
            //    thresholdTable.TableName = title + "Threshold";

            //    graphType = Enumerators.GraphType.Threshold;

            //    if (thresholdTable.Rows.Count > 1)
            //        result.Add(new Charts(thresholdTable, graphType));
            //    else
            //        result.Add(new Lists(thresholdTable));
            //}

            return(result);
        }