using SolarPower.Models; using SolarPower.Models.PowerStation; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace SolarPower.Services.Implement { public class MyPowerStationService { private readonly IPowerStationRepository powerStationRepository; public MyPowerStationService(IPowerStationRepository powerStationRepository) { this.powerStationRepository = powerStationRepository; } public List GetMyCities(MyUser myUser, byte showEnable = 1) { List myCities = new List(); myCities = powerStationRepository.GetMyCities(myUser, showEnable); return myCities; } public List GetMyPowerStations(MyUser myUser, byte showEnable = 1, List cityIds = null, List wheres = null, Dictionary where_entities = null, List orderBy = null) { List powerStations = new List(); powerStations = powerStationRepository.GetMyPowerStationList(myUser, showEnable, cityIds, wheres, where_entities, orderBy); return powerStations; } public List GetMyPowerStationsGroupByCity(MyUser myUser, List cityIds = null, List wheres = null, Dictionary where_entities = null, List orderBy = null) { List powerStations = new List(); powerStations = powerStationRepository.GetMyPowerStationList(myUser,1, cityIds, wheres, where_entities, orderBy); var myPowerStations_group = powerStations.GroupBy(x => x.CityId); List myPowerStationGroupByCities = new List(); foreach (var powerStations_group_item in myPowerStations_group) { MyPowerStationGroupByCity myPowerStationGroupByCity = new MyPowerStationGroupByCity(); myPowerStationGroupByCity.CityId = powerStations_group_item.Key; myPowerStationGroupByCity.CityName = powerStations_group_item.First().CityName; myPowerStationGroupByCity.Amount = powerStations_group_item.Count(); myPowerStationGroupByCity.MyPowerStations = powerStations_group_item.ToList(); myPowerStationGroupByCities.Add(myPowerStationGroupByCity); } return myPowerStationGroupByCities; } public PowerStationsSummary GetMyPowerStationsSummary(List powerStations) { PowerStationsSummary powerStationsSummary = new PowerStationsSummary(); if(powerStations.Count() <= 0) { return powerStationsSummary; } var sum_Today_kwh = 0.0; var sum_Total_kwh = 0.0; var sum_Today_irradiance = 0.0; var sum_Avg_irradiance = 0.0; var sum_Today_PR = 0.0; var sum_Avg_PR = 0.0; var sum_Today_kwhkwp = 0.0; var sum_Avg_kwhkwp = 0.0; var sum_Today_money = 0.0; var sum_Total_money = 0.0; var sum_Today_carbon = 0.0; var sum_Total_carbon = 0.0; var count_powerStation = powerStations.Count(); foreach (var powerStation in powerStations) { sum_Today_kwh += powerStation.Today_kWh; sum_Total_kwh += powerStation.Total_kWh; sum_Today_irradiance += powerStation.Today_irradiance; sum_Avg_irradiance += powerStation.Avg_irradiance; sum_Today_PR += powerStation.Today_PR; sum_Avg_PR += powerStation.Avg_PR; sum_Today_kwhkwp += powerStation.Today_kwhkwp; sum_Avg_kwhkwp += powerStation.Avg_kwhkwp; sum_Today_money += powerStation.Today_Money; sum_Total_money += powerStation.Total_Money; sum_Today_carbon += powerStation.Today_Carbon; sum_Total_carbon += powerStation.Total_Carbon; } powerStationsSummary.Today_kwh = sum_Today_kwh; powerStationsSummary.Total_kwh = sum_Total_kwh; powerStationsSummary.Today_irradiance = sum_Today_irradiance / count_powerStation; powerStationsSummary.Avg_irradiance = sum_Avg_irradiance / count_powerStation; powerStationsSummary.Today_PR = sum_Today_PR / count_powerStation; powerStationsSummary.Avg_PR = sum_Avg_PR / count_powerStation; powerStationsSummary.Today_kwhkwp = sum_Today_kwhkwp / count_powerStation; powerStationsSummary.Avg_kwhkwp = sum_Avg_kwhkwp / count_powerStation; powerStationsSummary.Today_money = sum_Today_money; powerStationsSummary.Total_money = sum_Total_money; powerStationsSummary.Today_carbon = sum_Today_carbon; powerStationsSummary.Total_carbon = sum_Total_carbon; return powerStationsSummary; } } }