tbf/TBF/Rig/DataContainers/Evaporation/Component.cs
2023-04-19 12:06:16 +02:00

92 lines
3.7 KiB
C#

///
/// Copyright (c) 2020-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using Config.Entities;
using TBF.Rig.GenericDevices;
using TBF.Resources;
using TBF.UI.Calendar;
namespace TBF.Rig.DataContainers.Evaporation
{
public class Component : ComponentBase, IEvaporation, GenericDevices.IHasCalendarEvents
{
private static readonly ILog log = LogManager.GetLogger(typeof(Component));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly EvaporationCfg myCfg;
/// <summary>
/// For a given temperature in [°C] returns an evaporation rate in [kg/s]
/// </summary>
public double EvaporationRate(double temperature)
{
return MeasurementCorrection.GetCorrection(temperature, Corrections) / 3600.0; /// Converted from kg/h to kg/s
}
public Component() { }
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
myCfg = cfg as EvaporationCfg;
}
public override void Initialize()
{
log.FatalFormat("{0} initialized: {1}", Name, this);
}
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
DateTime calibDue = myCfg.CalibValidDate;
if (calibDue > TBF.UI.Constants.MinDate)
{
/// Five weekly notifications
foreach (var days in new int[] { -35, -28, -21, -14 })
{
if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
{
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
/// Five daily warnings
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
{
if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
{
/// Weekly reminders (last 5 weeks)
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
calibDue.Date.AddDays(days),
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
/// Calibration due date
if (calibDue.Date >= DateTime.Now.Date)
{
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
Name,
string.Format(Strings.Calibration_due_date_is_0,
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
}
}
return calEvents;
}
}
}