58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Web;
|
|||
|
|
|||
|
namespace Weee.Models.ExtensionMethods
|
|||
|
{
|
|||
|
public static class PowerUsageExtension
|
|||
|
{
|
|||
|
public static decimal GetTotalPowerPeak(this ICollection<PowerUsage> powerUsages)
|
|||
|
{
|
|||
|
decimal totalPowerPeak = 0;
|
|||
|
foreach (var powerUsage in powerUsages) {
|
|||
|
if (powerUsage.Peak.HasValue) totalPowerPeak += powerUsage.Peak.Value;
|
|||
|
}
|
|||
|
|
|||
|
return totalPowerPeak;
|
|||
|
}
|
|||
|
|
|||
|
public static decimal GetTotalPowerHalfPeak(this ICollection<PowerUsage> powerUsages)
|
|||
|
{
|
|||
|
decimal totalPowerHalfPeak = 0;
|
|||
|
foreach (var powerUsage in powerUsages) {
|
|||
|
if (powerUsage.HalfPeak.HasValue) totalPowerHalfPeak += powerUsage.HalfPeak.Value;
|
|||
|
}
|
|||
|
|
|||
|
return totalPowerHalfPeak;
|
|||
|
}
|
|||
|
|
|||
|
public static decimal GetTotalPowerSaturdayHalfPeak(this ICollection<PowerUsage> powerUsages)
|
|||
|
{
|
|||
|
decimal totalPowerSaturdayHalfPeak = 0;
|
|||
|
foreach (var powerUsage in powerUsages) {
|
|||
|
if (powerUsage.SaturdayHalfPeak.HasValue) totalPowerSaturdayHalfPeak += powerUsage.SaturdayHalfPeak.Value;
|
|||
|
}
|
|||
|
|
|||
|
return totalPowerSaturdayHalfPeak;
|
|||
|
}
|
|||
|
|
|||
|
public static decimal GetTotalPowerOffPeak(this ICollection<PowerUsage> powerUsages)
|
|||
|
{
|
|||
|
decimal totalPowerOffPeak = 0;
|
|||
|
foreach (var powerUsage in powerUsages) {
|
|||
|
if (powerUsage.OffPeak.HasValue) totalPowerOffPeak += powerUsage.OffPeak.Value;
|
|||
|
}
|
|||
|
|
|||
|
return totalPowerOffPeak;
|
|||
|
}
|
|||
|
|
|||
|
public static decimal GetTotalPowerUsage(this ICollection<PowerUsage> powerUsages)
|
|||
|
{
|
|||
|
return powerUsages.GetTotalPowerPeak() +
|
|||
|
powerUsages.GetTotalPowerHalfPeak() +
|
|||
|
powerUsages.GetTotalPowerSaturdayHalfPeak() +
|
|||
|
powerUsages.GetTotalPowerOffPeak();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|