demo20230512/Models/ExtensionMethods/SheetDataExtension.cs

59 lines
2.5 KiB
C#
Raw Normal View History

2023-05-12 10:20:28 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Weee.Models.ExtensionMethods
{
public static class SheetDataExtension
{
public static decimal GetTotalKgCO2e<T>(this ICollection<T> sheetDatas) where T : SheetData
{
return sheetDatas.Sum(x => x.KgCO2e);
}
public static void UpdateKgCO2e(this SheetData self, decimal parametervalue)
{
self.KgCO2e = self.Scalar * parametervalue;
}
public static decimal GetWeightDistributeKgCO2e<T>(this ICollection<T> sheetDatas, ProductLCA productLca) where T : SheetData
{
var weightDistribute = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetDistributeWeight();
return weightDistribute;
}
public static decimal GetAreaDistributeKgCO2e<T>(this ICollection<T> sheetDatas, ProductLCA productLca) where T : SheetData
{
var areaDistribute = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetDistributeArea();
return areaDistribute;
}
public static decimal GetHourDistributeKgCO2e<T>(this ICollection<T> sheetDatas, ProductLCA productLca) where T : SheetData
{
var hourDistribte = sheetDatas.Sum(x => x.KgCO2e) * productLca.GetDistributeHour();
return hourDistribte;
}
public static decimal GetWeightDistributePercentage<T>(this ICollection<T> sheetDatas, ProductLCA productLca) where T : SheetData
{
var kgCO2Proportion = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetTotalFabKgCO2e();
var weightDistributeProportion = kgCO2Proportion / productLca.GetDistributeWeight();
return weightDistributeProportion * 100;
}
public static decimal GetAreaDistributePercentage<T>(this ICollection<T> sheetDatas, ProductLCA productLca) where T : SheetData
{
var kgCO2Proportion = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetTotalFabKgCO2e();
var areaDistribteProportion = kgCO2Proportion / productLca.GetDistributeArea();
return areaDistribteProportion * 100;
}
public static decimal GetHourDistributePercentage<T>(this ICollection<T> sheetDatas, ProductLCA productLca) where T : SheetData
{
var kgCO2Proportion = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetTotalFabKgCO2e();
var hourDistributeProportion = kgCO2Proportion * productLca.GetDistributeHour();
return hourDistributeProportion * 100;
}
}
}