R1_V2 reduce GSheet API calls
This commit is contained in:
@@ -15,9 +15,6 @@ public class T1R1V2Processor(
|
||||
LayersController controller,
|
||||
LogsController logsController)
|
||||
{
|
||||
private readonly SpreadsheetsResource.ValuesResource _googleSheetValues = googleSheetValues;
|
||||
private readonly LogsController _logsController = logsController;
|
||||
|
||||
public void Process(Layer processWorker)
|
||||
{
|
||||
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
||||
@@ -103,7 +100,7 @@ public class T1R1V2Processor(
|
||||
{
|
||||
if (dynamicCode.Desc1 == null)
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -117,7 +114,7 @@ public class T1R1V2Processor(
|
||||
var calc = new BaseCalc(dynamicCode.Desc1);
|
||||
if (!calc.IsFormulaCorrect())
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -134,7 +131,7 @@ public class T1R1V2Processor(
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -147,7 +144,7 @@ public class T1R1V2Processor(
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logsController.AddEntry(new LogEntry
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.Warning,
|
||||
@@ -189,7 +186,7 @@ public class T1R1V2Processor(
|
||||
{
|
||||
const string sheetId = "1pph-XowjlK5CIaCEV_A5buK4ceJ0Z0YoUlDI4VMkhhA";
|
||||
const string sheetName = "Raport_R1_V2_Eksport";
|
||||
var request = _googleSheetValues.Get(sheetId, "C4:EX4");
|
||||
var request = googleSheetValues.Get(sheetId, $"{sheetName}!C4:CL4");
|
||||
var response = request.Execute();
|
||||
|
||||
var r1 = db.Layers
|
||||
@@ -200,6 +197,12 @@ public class T1R1V2Processor(
|
||||
const int startRow = 6;
|
||||
|
||||
var codesRow = response.Values[0];
|
||||
|
||||
var valueRange = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>>()
|
||||
};
|
||||
|
||||
for (var i = 1; i <= 12; i++)
|
||||
{
|
||||
var values = new List<object>();
|
||||
@@ -217,18 +220,9 @@ public class T1R1V2Processor(
|
||||
values.Add("0");
|
||||
}
|
||||
}
|
||||
|
||||
var valueRange = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>> { values }
|
||||
};
|
||||
var update = _googleSheetValues.Update(valueRange, sheetId, $"{sheetName}!C{row}:XZ{row}");
|
||||
update.ValueInputOption =
|
||||
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
update.Execute();
|
||||
Thread.Sleep(1000);
|
||||
valueRange.Values.Add(values);
|
||||
}
|
||||
|
||||
|
||||
// sum
|
||||
var valuesSum = new List<object>();
|
||||
var emptyRow = new List<object>();
|
||||
@@ -247,55 +241,36 @@ public class T1R1V2Processor(
|
||||
valuesSum.Add("0");
|
||||
}
|
||||
}
|
||||
|
||||
// insert empty row before sum
|
||||
var valueRangeEmpty = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>> { emptyRow }
|
||||
};
|
||||
var updateEmpty = _googleSheetValues.Update(valueRangeEmpty, sheetId, $"{sheetName}!C{rowEmpty}:XZ{rowEmpty}");
|
||||
updateEmpty.ValueInputOption =
|
||||
|
||||
valueRange.Values.Add(emptyRow);
|
||||
valueRange.Values.Add(valuesSum);
|
||||
|
||||
var update = googleSheetValues.Update(valueRange, sheetId, $"{sheetName}!C7:CL20");
|
||||
update.ValueInputOption =
|
||||
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
updateEmpty.Execute();
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var valueRangeSum = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>> { valuesSum }
|
||||
};
|
||||
var updateSum = _googleSheetValues.Update(valueRangeSum, sheetId, $"{sheetName}!C{rowSum}:XZ{rowSum}");
|
||||
updateSum.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
updateSum.Execute();
|
||||
Thread.Sleep(1000);
|
||||
update.Execute();
|
||||
|
||||
// update time
|
||||
var timeUtc = new List<object>
|
||||
{
|
||||
r1!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
||||
};
|
||||
var valueRangeUtcTime = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>> { timeUtc }
|
||||
};
|
||||
var updateTimeUtc = _googleSheetValues.Update(valueRangeUtcTime, sheetId, $"{sheetName}!G1");
|
||||
updateTimeUtc.ValueInputOption =
|
||||
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
updateTimeUtc.Execute();
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
||||
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r1.ModifiedAt.ToUniversalTime(), warsawTimeZone);
|
||||
var timeWarsaw = new List<object>
|
||||
{
|
||||
warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
||||
};
|
||||
var valueRangeWarsawTime = new ValueRange
|
||||
var valueRangeTime = new ValueRange
|
||||
{
|
||||
Values = new List<IList<object>> { timeWarsaw }
|
||||
Values = new List<IList<object>> ()
|
||||
};
|
||||
var updateTimeWarsaw = _googleSheetValues.Update(valueRangeWarsawTime, sheetId, $"{sheetName}!G2");
|
||||
updateTimeWarsaw.ValueInputOption =
|
||||
valueRangeTime.Values.Add(timeUtc);
|
||||
valueRangeTime.Values.Add(timeWarsaw);
|
||||
|
||||
var updateTimeUtc = googleSheetValues.Update(valueRangeTime, sheetId, $"{sheetName}!G1:G2");
|
||||
updateTimeUtc.ValueInputOption =
|
||||
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
||||
updateTimeWarsaw.Execute();
|
||||
updateTimeUtc.Execute();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user