Exemple #1
0
        public void GetDataTableForTeamCheckCorrectResult(int id)
        {
            GoogleVisualizationDataTable dataTableForFirstTeam = new GoogleVisualizationDataTable();

            dataTableForFirstTeam.AddColumn("Date", "string");
            dataTableForFirstTeam.AddColumn("WinRate", "number");
            dataTableForFirstTeam.AddRow(new List <object> {
                "19.11.2016", 100
            });
            dataTableForFirstTeam.AddRow(new List <object> {
                "20.11.2016", 100
            });
            dataTableForFirstTeam.AddRow(new List <object> {
                "21.11.2016", 100
            });
            dataTableForFirstTeam.AddRow(new List <object> {
                "22.11.2016", 75
            });
            dataTableForFirstTeam.AddRow(new List <object> {
                "23.11.2016", 60
            });

            GoogleVisualizationDataTable dataTableForSecondTeam = new GoogleVisualizationDataTable();

            dataTableForSecondTeam.AddColumn("Date", "string");
            dataTableForSecondTeam.AddColumn("WinRate", "number");
            dataTableForSecondTeam.AddRow(new List <object> {
                "19.11.2016", 0
            });
            dataTableForSecondTeam.AddRow(new List <object> {
                "20.11.2016", 0
            });
            dataTableForSecondTeam.AddRow(new List <object> {
                "21.11.2016", 0
            });
            dataTableForSecondTeam.AddRow(new List <object> {
                "22.11.2016", 25
            });
            dataTableForSecondTeam.AddRow(new List <object> {
                "23.11.2016", 40
            });

            var    res            = this.chartService.GetDataTableForTeam(id);
            string recievedResult = JsonConvert.SerializeObject(res);

            if (id == 1)
            {
                string expectedResult = JsonConvert.SerializeObject(dataTableForFirstTeam);
                Assert.AreEqual(expectedResult, recievedResult);
            }
            else if (id == 2)
            {
                string expectedResult = JsonConvert.SerializeObject(dataTableForSecondTeam);
                Assert.AreEqual(expectedResult, recievedResult);
            }
        }
        private GoogleVisualizationDataTable ConstructDataTableArea2(List <VentasSucAnioVsAnioAnterior> data)
        {
            var dataTable = new GoogleVisualizationDataTable();


            var anios = data.Select(x => x.Anio).Distinct().OrderBy(x => x);

            // Obtiene los dias del mes a mostrar
            var meses = data.Select(x => x.Mes).Distinct().OrderBy(x => x);

            // Define Columna y Tipo de variable
            dataTable.AddColumn("Año", "number");
            foreach (var anio in anios)
            {
                dataTable.AddColumn(anio.ToString(), "number");
            }

            foreach (var mes in meses)
            {
                var values = new List <object>(new[] { mes.ToString() });
                foreach (var anio in anios)
                {
                    var ventat = data
                                 .Where(x => x.Anio == anio && x.Mes == mes)
                                 .Select(x => x.VentasTotal)
                                 .SingleOrDefault();
                    values.Add(ventat);
                }
                dataTable.AddRow(values);
            }

            return(dataTable);
        }
        public GoogleVisualizationDataTable GetDataTableForTeam(int id)
        {
            GoogleVisualizationDataTable dataTable = new GoogleVisualizationDataTable();

            dataTable.AddColumn("Date", "date");
            dataTable.AddColumn("WinRate", "number");

            // Get existing results for team ordered by date
            var results = this.unitOfWork.GetRepository <Team>().GetById(id).Results
                          .Where(r => r.Score != -1)
                          .OrderBy(result => result.SportEvent.Date)
                          .ToList();
            int winGamesCounter   = 0;
            int totalGamesCounter = 0;

            foreach (var result in results)
            {
                totalGamesCounter++;
                IList <object> row = new List <object>(2);
                row.Add(result.SportEvent.Date);

                var winners = result.SportEvent.Results.Where(r => r.Score == result.SportEvent.Results.Max(mr => mr.Score)).ToList();

                int winrate = 0;
                // If draw - adding last winrate
                if (winners.Count > 1)
                {
                    if (dataTable.Rows.Count == 0)
                    {
                        continue;
                    }
                    winrate = int.Parse(dataTable.Rows[dataTable.Rows.Count - 1].C.ElementAt(1).V.ToString());
                    totalGamesCounter--;
                }
                else if (winners.Count == 1 && winners[0].Team.Id == id)
                {
                    winGamesCounter++;
                    winrate = winGamesCounter * 100 / totalGamesCounter;
                }
                else
                {
                    winrate = winGamesCounter * 100 / totalGamesCounter;
                }
                row.Add(winrate);

                dataTable.AddRow(row);
            }

            return(dataTable);
        }
Exemple #4
0
            protected void GetDatas(GoogleVisualizationDataTable dataTable, Dictionary <string, int> tableIndex)
            {
                CloudTable _table0 = GetTable(0);
                TableQuery <DynamicTableEntity> tableQuery = new TableQuery <DynamicTableEntity>().Where(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Data"));

                var maxCols = dataTable.cols.Count;
                TableContinuationToken continuationToken = null;
                TableQuerySegment <DynamicTableEntity> tableQueryResult = _table0.ExecuteQuerySegmentedAsync(tableQuery, continuationToken).Result;



                foreach (DynamicTableEntity tableEntity in tableQueryResult.Results)
                {
                    IDictionary <string, EntityProperty> nameInfos = tableEntity.Properties;
                    List <int> list = new List <int>();
                    foreach (KeyValuePair <string, EntityProperty> pInfo in nameInfos)
                    {
                        if (pInfo.Key == "Body")
                        {
                            continue;
                        }
                        list.Add((int)pInfo.Value.Int32Value);
                    }
                    list.Sort();

                    var values = new List <GoogleVisualizationDataTable.Row.RowValue>();
                    foreach (var item in tableIndex)
                    {
                        values.Add(new GoogleVisualizationDataTable.Row.RowValue(null, TDS7130_FORMAT.kDefDblFmtFlg));
                    }

                    bool addDate = true;
                    foreach (int index in list)
                    {
                        CloudTable  _table      = GetTable(index);
                        TableResult tableResult = _table.ExecuteAsync(TableOperation.Retrieve <DynamicTableEntity>("Data", tableEntity.RowKey)).Result;
                        if (tableResult.Result != null)
                        {
                            AddDataTableRow(maxCols, values, (DynamicTableEntity)tableResult.Result, ref addDate, tableIndex);
                        }
                    }
                    dataTable.AddRow(values);
                }
            }
Exemple #5
0
            protected void GetErrors(GoogleVisualizationDataTable dataTable)
            {
                CloudTable _table0 = GetTable(0);
                TableQuery <DynamicTableEntity> tableQuery = new TableQuery <DynamicTableEntity>().Where(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Error"));

                var maxCols = dataTable.cols.Count;
                TableContinuationToken continuationToken = null;
                TableQuerySegment <DynamicTableEntity> tableQueryResult = _table0.ExecuteQuerySegmentedAsync(tableQuery, continuationToken).Result;

                foreach (DynamicTableEntity tableEntity in tableQueryResult.Results)
                {
                    var values = new List <GoogleVisualizationDataTable.Row.RowValue>();
                    values.Add(new GoogleVisualizationDataTable.Row.RowValue(tableEntity.Properties["N001"].StringValue, TDS7130_FORMAT.kDefFmtFlg));
                    values.Add(new GoogleVisualizationDataTable.Row.RowValue(tableEntity.Properties["N002"].StringValue, TDS7130_FORMAT.kDefFmtFlg));
                    dataTable.AddRow(values);
                }
            }
        /// <summary>
        /// Gets the heart rate.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// Heartrate data in JSON format.
        /// </returns>
        public async Task <JsonResult> GetHeartRate(string startDate, CancellationToken cancellationToken)
        {
            var authResult = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata())
                             .AuthorizeAsync(cancellationToken);

            if (authResult.Credential != null)
            {
                try
                {
                    var service = new FitnessService(new BaseClientService.Initializer
                    {
                        ApiKey                = GoogleClientSettings.ApiKey,
                        ApplicationName       = GoogleClientSettings.ApplicationName,
                        HttpClientInitializer = authResult.Credential
                    });

                    var date  = DateTime.Parse(startDate).Date.ToUniversalTime();
                    var query = new HeartRateQuery(service);
                    var data  = query.QueryHeartRate(date, date.AddDays(1));

                    var dataTabe = new GoogleVisualizationDataTable();

                    dataTabe.AddColumn("Time", "string");
                    dataTabe.AddColumn("Heartrate", "number");

                    foreach (var dataPoint in data)
                    {
                        var values = new List <object>
                        {
                            dataPoint.TimeStamp.ToLocalTime().ToString("t"),
                            dataPoint.BPM
                        };
                        dataTabe.AddRow(values);
                    }
                    return(Json(dataTabe, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    Debug.WriteLine("e: " + e.Message);
                    return(Json(string.Empty));
                }
            }
            return(Json(string.Empty));
        }
Exemple #7
0
        private GoogleVisualizationDataTable ConstructDataTable(MarketSales[] data)
        {
            var dataTable = new GoogleVisualizationDataTable();

            // Get distinct markets from the data
            var markets = data.Select(x => x.Market).Distinct().OrderBy(x => x);

            // Get distinct years from the data
            var years = data.Select(x => x.Year).Distinct().OrderBy(x => x);

            // Specify the columns for the DataTable.
            // In this example, it is Market and then a column for each year.
            dataTable.AddColumn("", "string");
            foreach (var year in years)
            {
                dataTable.AddColumn(year.ToString(), "number");
            }

            // Specify the rows for the DataTable.
            // Each Market will be its own row, containing the total sales for each year.
            foreach (var market in markets)
            {
                var values = new List <object>(new[] { market });
                foreach (var year in years)
                {
                    var totalSales = data
                                     .Where(x => x.Market == market)
                                     .Select(x => x.Count)
                                     .SingleOrDefault();
                    values.Add(totalSales);
                }
                dataTable.AddRow(values);
            }


            return(dataTable);
        }
        private GoogleVisualizationDataTable ConstructDataTable(VentasRestaurant[] data)
        {
            var dataTable = new GoogleVisualizationDataTable();

            // Get distinct markets from the data
            var markets = data.Select(x => x.Sucursal).Distinct().OrderBy(x => x);

            // Get distinct years from the data
            var years = data.Select(x => x.Anio).Distinct().OrderBy(x => x);

            // Specify the columns for the DataTable.
            // In this example, it is Sucursal and then a column for each year.
            dataTable.AddColumn("Sucursal", "string");
            foreach (var year in years)
            {
                dataTable.AddColumn(year.ToString(), "number");
            }

            // Specify the rows for the DataTable.
            // Each Sucursal will be its own row, containing the total sales for each year.
            foreach (var Sucursal in markets)
            {
                var values = new List <object>(new[] { Sucursal });
                foreach (var year in years)
                {
                    var totalSales = data
                                     .Where(x => x.Sucursal == Sucursal && x.Anio == year)
                                     .Select(x => x.VentasTotales)
                                     .SingleOrDefault();
                    values.Add(totalSales);
                }
                dataTable.AddRow(values);
            }

            return(dataTable);
        }