예제 #1
0
 public void CreatErrorTable(out GoogleVisualizationDataTable dataTable)
 {
     dataTable = new GoogleVisualizationDataTable();
     dataTable.AddColumn("data", "string");
     dataTable.AddColumn("message", "string");
     GetErrors(dataTable);
 }
예제 #2
0
        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);
        }
예제 #3
0
            public void CreatDataTable(out GoogleVisualizationDataTable dataTable)
            {
                dataTable = new GoogleVisualizationDataTable();
                Dictionary <string, int> tableIndex = new Dictionary <string, int>();

                GetNames(dataTable, tableIndex);
                GetDatas(dataTable, tableIndex);
            }
예제 #4
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);
            }
        }
예제 #5
0
            protected void GetNames(GoogleVisualizationDataTable dataTable, Dictionary <string, int> tableIndex)
            {
                int              index          = 1;
                bool             addDate        = true;
                TableOperation   tableOperation = TableOperation.Retrieve <DynamicTableEntity>("Setting", "Name");
                CloudTableClient tableClient    = AzureStorageExtension.GetCloudTableClient(AzureStorageConfig);
                string           table0         = string.Format("{0}0", AzureStorageConfig.Container);

                TableContinuationToken token = new TableContinuationToken();

                do
                {
                    var orphanedTables = tableClient.ListTablesSegmentedAsync(AzureStorageConfig.Container, token).Result;
                    token = orphanedTables.ContinuationToken;
                    foreach (CloudTable cloudTable in orphanedTables.Results)
                    {
                        if (cloudTable.Name == table0)
                        {
                            continue;
                        }

                        DynamicTableEntity tdsTableEntity = (DynamicTableEntity)cloudTable.ExecuteAsync(tableOperation).Result.Result;
                        IDictionary <string, EntityProperty> nameInfos = tdsTableEntity.Properties;
                        string name = "";
                        foreach (KeyValuePair <string, EntityProperty> pInfo in nameInfos)
                        {
                            if (pInfo.Key != "PartitionKey" && pInfo.Key != "RowKey" && pInfo.Key != "Timestamp")
                            {
                                name = pInfo.Value.StringValue; //.GetValue(tdsTableEntity);
                                if (name == null)
                                {
                                    break;
                                }

                                if (pInfo.Key == "ADATE")
                                {
                                    if (addDate)
                                    {
                                        dataTable.AddColumn(name, "datetime");
                                        tableIndex.Add(pInfo.Key, 0);
                                        addDate = false;
                                    }
                                }
                                else
                                {
                                    dataTable.AddColumn(name, "number");
                                    tableIndex.Add(pInfo.Key, index++);
                                }
                            }
                        }
                    }
                }while (token != null);
            }
예제 #6
0
        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);
        }
예제 #7
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);
                }
            }
예제 #8
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));
        }
예제 #10
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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        public static string JsonSerializeGoogleVisualizationDataTable(GoogleVisualizationDataTable googleVisualizationDataTable)
        {
            MemoryStream memoryStream = null;
            StreamWriter streamWriter = null;
            StreamReader streamReader = null;

            try
            {
                memoryStream = new MemoryStream();
                streamWriter = new StreamWriter(memoryStream);
                // Start
                streamWriter.Write('{');

                #region Writing Json columns
                streamWriter.Write("cols:[");

                for (int i = 0; i < googleVisualizationDataTable.Columns.Count(); i++)
                {
                    GoogleVisualizationDataTableColumn column = googleVisualizationDataTable.Columns[i];

                    streamWriter.Write('{');

                    if (string.IsNullOrWhiteSpace(column.ColumnId) == false) streamWriter.Write(string.Format("id: '{0}',", column.ColumnId));
                    if (string.IsNullOrWhiteSpace(column.Label) == false) streamWriter.Write(string.Format("label: '{0}',", column.Label));
                    if (string.IsNullOrWhiteSpace(column.Pattern) == false) streamWriter.Write(string.Format("pattern: '{0}',", column.Pattern));
                    if (column.CustomProperties != null)
                    {
                        if (column.CustomProperties.Count() > 0)
                        {
                            streamWriter.Write("p: {");
                            foreach (KeyValuePair<string, object> pair in column.CustomProperties)
                            {
                                if (pair.Value != null)
                                    streamWriter.Write(string.Format("{0}: '{1}',", pair.Key, pair.Value));
                            }
                            streamWriter.Write("},");
                        }
                    }

                    streamWriter.Write(string.Format("type: '{0}'", Enum.GetName(typeof(GoogleVisualizationDataTableColumnType), column.ColumnType).ToLower()));

                    if (i != googleVisualizationDataTable.Columns.Count() - 1)
                        streamWriter.Write("},");
                    else
                        streamWriter.Write('}');
                }
                streamWriter.Write("],");
                #endregion

                #region Writing Json rows
                streamWriter.Write("rows:[");

                for (int j = 0; j < googleVisualizationDataTable.Rows.Count(); j++)
                {
                    GoogleVisualizationDataTableRow row = googleVisualizationDataTable.Rows[j];

                    streamWriter.Write("{c:[");


                    for (int i = 0; i < row.Cells.Count(); i++)
                    {
                        GoogleVisualizationDataTableRowCell cell = row.Cells[i];
                        streamWriter.Write("{");
                        if (cell.CellValue != null) streamWriter.Write(string.Format("v: {0}", GetCellValueBasedOnColumnType(googleVisualizationDataTable.Columns[i].ColumnType, cell.CellValue)));
                        if (string.IsNullOrWhiteSpace(cell.CellValueAsString) == false) streamWriter.Write(string.Format(", f: '{0}'", cell.CellValueAsString));

                        if (cell.CustomProperties != null)
                        {
                            if (cell.CustomProperties.Count() > 0)
                            {
                                streamWriter.Write(", p: {");
                                foreach (KeyValuePair<string, object> pair in cell.CustomProperties)
                                {
                                    if (pair.Value != null)
                                        streamWriter.Write(string.Format("{0}: '{1}',", pair.Key, pair.Value));
                                }
                                streamWriter.Write("}");
                            }
                        }

                        if (i != row.Cells.Count() - 1)
                            streamWriter.Write("},");
                        else
                            streamWriter.Write('}');
                    }

                    if (j != googleVisualizationDataTable.Rows.Count() - 1)
                        streamWriter.Write("]},");
                    else
                        streamWriter.Write("]}");
                }
                streamWriter.Write("]");
                #endregion

                #region Writing custom properties

                if (googleVisualizationDataTable.CustomProperties != null)
                {
                    if (googleVisualizationDataTable.CustomProperties.Count() > 0)
                    {
                        streamWriter.Write(", p: {");
                        foreach (KeyValuePair<string, object> pair in googleVisualizationDataTable.CustomProperties)
                        {
                            if (pair.Value != null)
                                streamWriter.Write(string.Format("{0}: '{1}',", pair.Key, pair.Value));
                        }
                        streamWriter.Write("}");
                    }
                }
                #endregion

                // End
                streamWriter.Write('}');

                streamWriter.Flush();

                memoryStream.Seek(0, SeekOrigin.Begin); // Rewind stream
                streamReader = new StreamReader(memoryStream);
                string content = streamReader.ReadToEnd();
                return (content);
            }
            finally
            {
                //if (memoryStream != null) memoryStream.Close();
                //if (streamWriter != null) streamWriter.Close();
                //if (streamReader != null) streamReader.Close();

                //memoryStream.Dispose();
                //streamWriter.Dispose();
                //streamReader.Dispose();
            }

            return null;
        }
예제 #13
0
        public static void JsonSerializeGoogleVisualizationDataTable(GoogleVisualizationDataTable googleVisualizationDataTable, ref MemoryStream memoryStream)
        {
            if (memoryStream == null)
                throw new ArgumentException("You need to supply an instantiated memory stream and pass it by reference to this method");

            StreamWriter streamWriter = null;

            try
            {
                memoryStream = new MemoryStream();
                streamWriter = new StreamWriter(memoryStream);
                // Start
                streamWriter.Write('{');

                #region Writing Json columns
                streamWriter.Write("cols:[");

                for (int i = 0; i < googleVisualizationDataTable.Columns.Count(); i++)
                {
                    GoogleVisualizationDataTableColumn column = googleVisualizationDataTable.Columns[i];

                    streamWriter.Write('{');

                    if (string.IsNullOrWhiteSpace(column.ColumnId) == false) streamWriter.Write(string.Format("id: '{0}',", column.ColumnId));
                    if (string.IsNullOrWhiteSpace(column.Label) == false) streamWriter.Write(string.Format("label: '{0}',", column.Label));
                    if (string.IsNullOrWhiteSpace(column.Pattern) == false) streamWriter.Write(string.Format("pattern: '{0}',", column.Pattern));
                    if (column.CustomProperties != null)
                    {
                        if (column.CustomProperties.Count() > 0)
                        {
                            streamWriter.Write("p: {");
                            foreach (KeyValuePair<string, object> pair in column.CustomProperties)
                            {
                                if (pair.Value != null)
                                    streamWriter.Write(string.Format("{0}: '{1}',", pair.Key, pair.Value));
                            }
                            streamWriter.Write("},");
                        }
                    }

                    streamWriter.Write(string.Format("type: '{0}'", Enum.GetName(typeof(GoogleVisualizationDataTableColumnType), column.ColumnType).ToLower()));

                    if (i != googleVisualizationDataTable.Columns.Count() - 1)
                        streamWriter.Write("},");
                    else
                        streamWriter.Write('}');
                }
                streamWriter.Write("],");
                #endregion

                #region Writing Json rows
                streamWriter.Write("rows:[");

                for (int j = 0; j < googleVisualizationDataTable.Rows.Count(); j++)
                {
                    GoogleVisualizationDataTableRow row = googleVisualizationDataTable.Rows[j];

                    streamWriter.Write("{c:[");


                    for (int i = 0; i < row.Cells.Count(); i++)
                    {
                        GoogleVisualizationDataTableRowCell cell = row.Cells[i];
                        streamWriter.Write("{");
                        if (cell.CellValue != null) streamWriter.Write(string.Format("v: {0}", GetCellValueBasedOnColumnType(googleVisualizationDataTable.Columns[i].ColumnType, cell.CellValue)));
                        if (string.IsNullOrWhiteSpace(cell.CellValueAsString) == false) streamWriter.Write(string.Format(", f: '{0}'", cell.CellValueAsString));

                        if (cell.CustomProperties != null)
                        {
                            if (cell.CustomProperties.Count() > 0)
                            {
                                streamWriter.Write(", p: {");
                                foreach (KeyValuePair<string, object> pair in cell.CustomProperties)
                                {
                                    if (pair.Value != null)
                                        streamWriter.Write(string.Format("{0}: '{1}',", pair.Key, pair.Value));
                                }
                                streamWriter.Write("}");
                            }
                        }

                        if (i != row.Cells.Count() - 1)
                            streamWriter.Write("},");
                        else
                            streamWriter.Write('}');
                    }

                    if (j != googleVisualizationDataTable.Rows.Count() - 1)
                        streamWriter.Write("]},");
                    else
                        streamWriter.Write("]}");
                }
                streamWriter.Write("]");
                #endregion

                #region Writing custom properties

                if (googleVisualizationDataTable.CustomProperties != null)
                {
                    if (googleVisualizationDataTable.CustomProperties.Count() > 0)
                    {
                        streamWriter.Write(", p: {");
                        foreach (KeyValuePair<string, object> pair in googleVisualizationDataTable.CustomProperties)
                        {
                            if (pair.Value != null)
                                streamWriter.Write(string.Format("{0}: '{1}',", pair.Key, pair.Value));
                        }
                        streamWriter.Write("}");
                    }
                }
                #endregion

                // End
                streamWriter.Write('}');

                streamWriter.Flush();
            }
            finally
            {
                streamWriter.Close();
            }
        }