public IActionResult InsertBQData(string username, string userplan, string customerId) { try { string projectId = "task8-imagerecognition-281418"; DateTime now = DateTime.Now; Console.WriteLine("email: " + username); Console.WriteLine("plan: " + userplan); BigQueryClient client = BigQueryClient.Create(projectId); // Create the dataset if it doesn't exist. BigQueryDataset dataset = client.GetOrCreateDataset("mydata"); // Create the table if it doesn't exist. BigQueryTable table = dataset.GetOrCreateTable("customer", new TableSchemaBuilder { { "email", BigQueryDbType.String }, { "subscriptionStarted", BigQueryDbType.Timestamp }, { "planType", BigQueryDbType.String } //BigQueryDbType.Int64 }.Build()); //Insert data into table table.InsertRow(new BigQueryInsertRow { { "email", username }, { "subscriptionStarted", DateTimeOffset.UtcNow.ToUnixTimeSeconds() }, { "planType", userplan } }); Console.WriteLine("Inserted: " + username + " successfully"); return(Redirect("/Home/Main/" + username + "/" + userplan + "/" + customerId + "?Msg=Success")); }// End of try catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(Redirect("/Home/Main/" + username + "/" + userplan + "/" + customerId + "?Msg=Failed")); } }// End of insertBQData
private void btnAddData_Click(object sender, EventArgs e) { //var credentials = GoogleCredential.FromFile(jsonPath); //var client = BigQueryClient.Create(projectId, credentials); // Create the table if it doesn't exist. BigQueryTable table = dataset.GetOrCreateTable("Test_Data_Recipe", new TableSchemaBuilder { { "LogTime", BigQueryDbType.Timestamp }, { "SampleName", BigQueryDbType.String }, { "CycleNumber", BigQueryDbType.Int64 }, { "Epoch", BigQueryDbType.Int64 }, { "TotalTime", BigQueryDbType.Int64 }, { "TimeIntoCycle", BigQueryDbType.Int64 }, { "CurrentBias", BigQueryDbType.Bool }, { "Current", BigQueryDbType.Float64 }, { "Voltage", BigQueryDbType.Float64 }, { "EstimatedRs", BigQueryDbType.Float64 }, { "Temps", BigQueryDbType.Float64, BigQueryFieldMode.Repeated }, { "SmokeVoltage", BigQueryDbType.Float64, BigQueryFieldMode.Repeated }, { "SmokeLevel", BigQueryDbType.Float64, BigQueryFieldMode.Repeated }, { "NumCells", BigQueryDbType.Int64 }, { "CellVoc", BigQueryDbType.Float64 }, { "TempSensor", BigQueryDbType.Int64 }, { "SetCurrent", BigQueryDbType.Float64 }, }.Build()); // Insert a single row. There are many other ways of inserting // data into a table. var now = DateTime.UtcNow; var dt = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond); //string currentdatetime = DateTime.Now.ToUniversalTime().ToString("yyyyMMdd[HH:mm:ss]"); for (var i = 0; i < 200; i++) { now = DateTime.UtcNow; dt = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond); table.InsertRow(new BigQueryInsertRow { { "LogTime", dt }, { "SampleName", "Test1" }, { "CycleNumber", 11 }, { "Epoch", 1 }, { "TotalTime", 2 }, { "TimeIntoCycle", 3 }, { "CurrentBias", false }, { "Current", 4 }, { "Voltage", 5 }, { "EstimatedRs", 6 }, { "Temps", new List <double> { 60, 60 } }, { "SmokeVoltage", new List <double> { 60, 60 } }, { "SmokeLevel", new List <double> { 60, 60 } }, { "NumCells", 8 }, { "CellVoc", 9 }, { "TempSensor", 9 }, { "SetCurrent", 99 }, }); } }
private void SaveCCData(CCDataPoint d) { if (ComputerName != "CH-J7TMTZ1") { try { if (BuildTable()) { _table.InsertRow(new BigQueryInsertRow { { "CycleNumber", d.CycleNumber }, { "LogTime_Timestamp", d.LogTime }, { "TotalTest_Hours", d.TotalTime }, { "MinutesIntoCycle", d.TimeIntoCycle }, { "CurrentBiasIsOn", d.CurrentBias ? "ON" : "OFF" }, { "SampleName", d.SampleName }, { "Current_Amps", d.Current }, { "Voltage_Volts", d.Voltage }, { "NumCells", d.NumCells }, { "CellVoc_Volts", d.CellVoc }, { "TempSensorNumber", d.TempSensor }, { "SetCurrent_Amps", d.SetCurrent }, { "EstimatedRs_mOhms", d.EstimatedRs }, { "Temp1_C", d.Temps[0] }, { "Temp2_C", d.Temps[1] }, { "Temp3_C", d.Temps[2] }, { "Temp4_C", d.Temps[3] }, { "Temp5_C", d.Temps[4] }, { "Temp6_C", d.Temps[5] }, { "Temp7_C", d.Temps[6] }, { "Temp8_C", d.Temps[7] }, { "Temp9_C", d.Temps[8] }, { "Temp10_C", d.Temps[9] }, { "Temp11_C", d.Temps[10] }, { "Temp12_C", d.Temps[11] }, { "Temp13_C", d.Temps[12] }, { "Temp14_C", d.Temps[13] }, { "Temp15_C", d.Temps[14] }, { "Temp16_C", d.Temps[15] }, { "SmokeLevel1_Volts", d.SmokeLevel[0] }, { "SmokeLevel2_Volts", d.SmokeLevel[1] }, { "SmokeLevel3_Volts", d.SmokeLevel[2] }, { "SmokeLevel4_Volts", d.SmokeLevel[3] }, { "SmokeLevel5_Volts", d.SmokeLevel[4] }, { "SmokeLevel6_Volts", d.SmokeLevel[5] }, { "SmokeLevel7_Volts", d.SmokeLevel[6] }, { "SmokeLevel8_Volts", d.SmokeLevel[7] }, { "SmokeVoltage1_Volts", d.SmokeVoltage[0] }, { "SmokeVoltage2_Volts", d.SmokeVoltage[1] }, { "SmokeVoltage3_Volts", d.SmokeVoltage[2] }, { "SmokeVoltage4_Volts", d.SmokeVoltage[3] }, { "SmokeVoltage5_Volts", d.SmokeVoltage[4] }, { "SmokeVoltage6_Volts", d.SmokeVoltage[5] }, { "SmokeVoltage7_Volts", d.SmokeVoltage[6] }, { "SmokeVoltage8_Volts", d.SmokeVoltage[7] }, }); } else { U.Logger.WriteLine("Google BQ connection ERROR. Backing up via CSV"); } } catch (Exception exc) { U.Logger.WriteLine(exc.ToString()); } } try { SaveCSVResults(d); } catch (Exception exc) { U.Logger.WriteLine(exc.ToString()); } }
private void SaveCCData(CCDataPoint d) { try { //IDictionary<String, Object> dictionary = d.GetType() // .GetProperties() // .Where(p => p.CanRead) // .ToDictionary(p => p.Name, p => p.GetValue(d, null)); //foreach (var dd in dictionary) Console.WriteLine($"{dd}"); if (BuildTable()) { _table.InsertRow(new BigQueryInsertRow { { "CycleNumber", d.CycleNumber }, { "LogTime_Timestamp", d.LogTime }, { "TotalTest_Hours", d.TotalTime }, { "MinutesIntoCycle", d.TimeIntoCycle }, { "CurrentBiasIsOn", d.CurrentBias ? "ON" : "OFF" }, { "SampleName", d.SampleName }, { "Current_Amps", d.Current }, { "Voltage_Volts", d.Voltage }, { "NumCells", d.NumCells }, { "CellVoc_Volts", d.CellVoc }, { "TempSensorNumber", d.TempSensor }, { "SetCurrent_Amps", d.SetCurrent }, { "EstimatedRs_mOhms", d.EstimatedRs }, { "Temp1_C", d.Temps[0] }, { "Temp2_C", d.Temps[1] }, { "Temp3_C", d.Temps[2] }, { "Temp4_C", d.Temps[3] }, { "Temp5_C", d.Temps[4] }, { "Temp6_C", d.Temps[5] }, { "Temp7_C", d.Temps[6] }, { "Temp8_C", d.Temps[7] }, { "Temp9_C", d.Temps[8] }, { "Temp10_C", d.Temps[9] }, { "Temp11_C", d.Temps[10] }, { "Temp12_C", d.Temps[11] }, { "Temp13_C", d.Temps[12] }, { "Temp14_C", d.Temps[13] }, { "Temp15_C", d.Temps[14] }, { "Temp16_C", d.Temps[15] }, { "SmokeLevel1_Volts", d.SmokeLevel[0] }, { "SmokeLevel2_Volts", d.SmokeLevel[1] }, { "SmokeLevel3_Volts", d.SmokeLevel[2] }, { "SmokeLevel4_Volts", d.SmokeLevel[3] }, { "SmokeLevel5_Volts", d.SmokeLevel[4] }, { "SmokeLevel6_Volts", d.SmokeLevel[5] }, { "SmokeLevel7_Volts", d.SmokeLevel[6] }, { "SmokeLevel8_Volts", d.SmokeLevel[7] }, { "SmokeVoltage1_Volts", d.SmokeVoltage[0] }, { "SmokeVoltage2_Volts", d.SmokeVoltage[1] }, { "SmokeVoltage3_Volts", d.SmokeVoltage[2] }, { "SmokeVoltage4_Volts", d.SmokeVoltage[3] }, { "SmokeVoltage5_Volts", d.SmokeVoltage[4] }, { "SmokeVoltage6_Volts", d.SmokeVoltage[5] }, { "SmokeVoltage7_Volts", d.SmokeVoltage[6] }, { "SmokeVoltage8_Volts", d.SmokeVoltage[7] }, }); } else { throw new Exception(); } } catch { Console.WriteLine("Google BQ connection ERROR. Backing up via CSV"); SaveResults(d); } }