public DamageFromAttack(SourceHistory sourceHistory, float damageScale, bool isHpPercent, float weight, float skillPowerScale, int casterId, Vector2 projectilePosition, Vector2 impactPosition, BakedStatsContainer characterStats, bool forceAddModifier = false, DeathBehavior deathBehavior = CastProjectileAction.DeathBehavior.Neutral, bool requireCasterToBeAlive = true, bool isHpPercentBaseOnMaxHp = false) { if (characterStats == null) { throw new Exception("null character stats"); } this.sourceHistory = sourceHistory; this.damageScale = damageScale; this.isHpPercent = isHpPercent; this.weight = weight; this.skillPowerScale = skillPowerScale; this.casterId = casterId; this.projectilePosition = projectilePosition; this.impactPosition = impactPosition; this.characterStats = characterStats; this.forceAddModifier = forceAddModifier; this.deathBehavior = deathBehavior; this.requireCasterToBeAlive = requireCasterToBeAlive; this.isHpPercentBaseOnMaxHp = isHpPercentBaseOnMaxHp; }
public async Task <IActionResult> GetSourceData( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "sourcedata/{sourceId}")] HttpRequest req, [CosmosDB("dashboard", "sourcedata", ConnectionStringSetting = "CosmosDbConnectionString")] DocumentClient docClient, string sourceId, ILogger log) { log.LogInformation($"Getting source data for '{sourceId}'"); var configItemsToProcess = new List <SourceConfig>(); if (int.TryParse(req.Query["numdatapoints"], out int numDataPoints)) { log.LogInformation($"Number of data points was specified: '{1}'"); } else { numDataPoints = 1; } var sensitiveDataPin = _config["SensitiveDataPin"]; bool isSensitiveDataPinPresent = Helpers.IsSensitiveDataPinProvided(sensitiveDataPin, req); var collectionUri = UriFactory.CreateDocumentCollectionUri("dashboard", "sourcedata"); // SELECT TOP 2 * FROM c WHERE c.SourceId='solar' ORDER BY c.TimeStampUtc DESC var query = docClient .CreateDocumentQuery <SourceData>(collectionUri) .Where(x => x.SourceId == sourceId) .OrderByDescending(x => x.TimeStampUtc) .Take(numDataPoints) .AsDocumentQuery(); var dataHistoryItems = new List <SourceData>(); while (query.HasMoreResults) { var documents = await query.ExecuteNextAsync <SourceData>(); // Filter all data items in the document and exclude sensitive ones if the PIN is not provided. foreach (var document in documents) { document.DataItems = document .DataItems .Where(x => !x.IsSensitive || isSensitiveDataPinPresent) .ToArray(); } dataHistoryItems.AddRange(documents); } var result = new SourceHistory { SourceId = sourceId, HistoryData = dataHistoryItems.ToArray() }; return(new OkObjectResult(result)); }
async Task RefreshUI(SourceHistory history) { var labels = history.HistoryData .Select(d => d.TimeStampUtc.LocalDateTime.ToString("d.M.")) .Reverse() .ToArray(); var dataSupplies = history.HistoryData .Select(d => { // Item 0 = supplies in kg (label "supplies") string value = d.DataItems[0].Value.ToString(); double.TryParse(value, out double supplies); return(supplies); }) .Reverse() .ToList(); var currentSupplies = $"Vorrat: {dataSupplies.Last():0.0}kg"; var dataSetPelletSupplies = new LineChartDataset <double> { Label = currentSupplies, Data = dataSupplies, BackgroundColor = new List <string> { ChartColor.FromRgba(226, 228, 242, 0.8f) }, BorderColor = new List <string> { ChartColor.FromRgba(95, 104, 188, 0.5f) }, Fill = true, PointRadius = 2, BorderDash = new List <int> { } }; await lineChart.Clear(); await lineChart.AddLabel(labels); await lineChart.AddDataSet(dataSetPelletSupplies); await lineChart.Update(); }
void RefreshUI(SourceHistory history) { if (history?.HistoryData != null && history.HistoryData.Length > 0 && history.HistoryData[0].DataItems != null && history.HistoryData[0].DataItems.Length > 0) { _wodDate = history.HistoryData[0].TimeStampUtc.UtcDateTime; TimeStampSource = _wodDate.ToLocalTime().ToString("g"); WodHtml = history.HistoryData[0].DataItems[0].Value.ToString(); if (string.IsNullOrWhiteSpace(WodHtml)) { WodHtml = "Leider kein WOD gefunden :-("; } } else { TimeStampSource = _wodDate.ToLocalTime().ToString("g"); WodHtml = "Leider kein WOD gefunden :-("; } }
async Task RefreshUI(SourceHistory history) { // We're only retrieving one item. var singleSourceData = history.HistoryData[0]; var vehicleStateItem = singleSourceData.DataItems.First(x => x.Id == "vehicle_state"); var vehicleState = Convert.ToString(vehicleStateItem.Value); if (vehicleState != "online") { IsCarOffline = true; } else { IsCarOffline = false; var chargeLevelPercentItem = history.HistoryData[0].DataItems.First(x => x.Id == "charge_level_percent"); ChargeLevelPercent = Convert.ToInt32(chargeLevelPercentItem.Value); var carTemperatureItem = history.HistoryData[0].DataItems.First(x => x.Id == "inside_temperature"); CarTemperature = $"{Math.Round(Convert.ToDouble(carTemperatureItem.Value))}°"; } await JSRuntime.InvokeVoidAsync("updateBingMap", 47.855042, 12.185040); }
async Task RefreshUI(SourceHistory history) { var labels = history.HistoryData .Select(d => d.TimeStampUtc.LocalDateTime.ToString("HH:mm")) .Reverse() .ToArray(); var dataHousePower = history.HistoryData .Select(d => { string value = d.DataItems[1].Value.ToString(); double.TryParse(value, out double power); return(power); }) .Reverse() .ToList(); var dataSolarPower = history.HistoryData .Select(d => { string value = d.DataItems[2].Value.ToString(); double.TryParse(value, out double power); return(power); }) .Reverse() .ToList(); var productionEnergy = $"PV ({dataSolarPower.Last():0.#}kW)"; var consumptionEnergy = $"Verbrauch ({dataHousePower.Last():0.#}kW)"; var dataSetHousePower = new LineChartDataset <double> { Label = consumptionEnergy, Data = dataHousePower, BackgroundColor = new List <string> { ChartColor.FromRgba(249, 134, 134, 0.5f) }, BorderColor = new List <string> { ChartColor.FromRgba(249, 134, 134, 1f) }, Fill = true, PointRadius = 2, BorderDash = new List <int> { } }; var dataSetSolarPower = new LineChartDataset <double> { Label = productionEnergy, Data = dataSolarPower, Fill = true, BackgroundColor = new List <string> { ChartColor.FromRgba(226, 228, 242, 0.8f) }, BorderColor = new List <string> { ChartColor.FromRgba(95, 104, 188, 0.5f) }, PointRadius = 2, BorderDash = new List <int> { } }; await lineChart.Clear(); await lineChart.AddLabel(labels); await lineChart.AddDataSet(dataSetHousePower); await lineChart.AddDataSet(dataSetSolarPower); await lineChart.Update(); }
public async Task <IActionResult> GetSourceDataFiltered( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "sourcedata")] HttpRequest req, [CosmosDB("dashboard", "sourcedata", ConnectionStringSetting = "CosmosDbConnectionString")] DocumentClient docClient, ILogger log) { log.LogInformation("Getting filtered source data."); Filter filter = null; try { filter = JsonConvert.DeserializeObject <Filter>(await req.ReadAsStringAsync()); } catch (System.Exception ex) { return(new BadRequestObjectResult("Error deserializing Filter from request body: " + ex)); } var configItemsToProcess = new List <SourceConfig>(); var sensitiveDataPin = _config["SensitiveDataPin"]; bool isSensitiveDataPinPresent = Helpers.IsSensitiveDataPinProvided(sensitiveDataPin, req); var collectionUri = UriFactory.CreateDocumentCollectionUri("dashboard", "sourcedata"); IQueryable <SourceData> query = docClient.CreateDocumentQuery <SourceData>(collectionUri); // Filter by source ID. string sourceId = null; if (!string.IsNullOrWhiteSpace(filter.SourceId)) { sourceId = filter.SourceId.ToLowerInvariant().Trim(); query = query.Where(x => x.SourceId == sourceId); } // Filter by start date. if (filter.StartDateUtc.HasValue) { query = query.Where(x => x.TimeStampUtc >= filter.StartDateUtc); } // Filter by end date. if (filter.EndDateUtc.HasValue) { query = query.Where(x => x.TimeStampUtc < filter.EndDateUtc); } var filterQuery = query .OrderByDescending(x => x.TimeStampUtc) .Take(filter.TakeNumberResults.HasValue ? filter.TakeNumberResults.Value : int.MaxValue) .AsDocumentQuery(); var dataHistoryItems = new List <SourceData>(); while (filterQuery.HasMoreResults) { var documents = await filterQuery.ExecuteNextAsync <SourceData>(); // Filter all data items in the document and exclude sensitive ones if the PIN is not provided. foreach (var document in documents) { document.DataItems = document .DataItems .Where(x => !x.IsSensitive || isSensitiveDataPinPresent) .ToArray(); } dataHistoryItems.AddRange(documents); } var result = new SourceHistory { SourceId = sourceId, HistoryData = dataHistoryItems.ToArray() }; return(new OkObjectResult(result)); }