211 lines
6.4 KiB
C#
211 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web.Http;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace Thermo.Active.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/report")]
|
|
public class ReportController : ApiController
|
|
{
|
|
[Route("data")]
|
|
public IHttpActionResult GetReportData()
|
|
{
|
|
StreamReader sr = new StreamReader("./Report/PieAndData.xml");
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(DTOReportData));
|
|
DTOReportData schema = xmlSerializer.Deserialize(sr) as DTOReportData;
|
|
|
|
return Ok(schema);
|
|
}
|
|
|
|
[Route("pieChart"), HttpPost]
|
|
public IHttpActionResult GetPieChartData(DTODateFilter filter)
|
|
{
|
|
StreamReader sr = new StreamReader("./Report/PieAndData.xml");
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(DTOPieChart));
|
|
DTOPieChart schema = xmlSerializer.Deserialize(sr) as DTOPieChart;
|
|
|
|
return Ok(schema);
|
|
}
|
|
|
|
[Route("timeLine"), HttpPost]
|
|
public IHttpActionResult GetTimelineData(DTONameFilter filter)
|
|
{
|
|
StreamReader sr = new StreamReader("./Report/TimeLine.xml");
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(DTOTimeline));
|
|
DTOTimeline schema = xmlSerializer.Deserialize(sr) as DTOTimeline;
|
|
|
|
return Ok(schema);
|
|
}
|
|
|
|
[Route("programs"), HttpPost]
|
|
public IHttpActionResult GetProgramHistoryData(DTOPageAndFilterModel filter)
|
|
{
|
|
StreamReader sr = new StreamReader("./Report/Programs.xml");
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(DTOHistogramModel));
|
|
DTOHistogramModel schema = xmlSerializer.Deserialize(sr) as DTOHistogramModel;
|
|
|
|
// FIlter
|
|
schema.Occurrences = schema.Occurrences.Where(x =>
|
|
x.ProgName.Contains(filter.Name) &&
|
|
DateTime.Parse(x.StartDate) >= filter.StartDate && DateTime.Parse(x.EndDate) <= filter.EndDate
|
|
)
|
|
.ToList();
|
|
|
|
// Count pages
|
|
schema.Pages = (int)Math.Ceiling((double)schema.Occurrences.Count() / (double)filter.PageSize);
|
|
// Skip previous pages
|
|
schema.Occurrences = schema
|
|
.Occurrences
|
|
.Skip(filter.Page - 1 * filter.PageSize)
|
|
.Take(filter.PageSize)
|
|
.ToList();
|
|
|
|
return Ok(schema);
|
|
}
|
|
|
|
public class DTODateFilter
|
|
{
|
|
public DateTime StartDate { get; set; }
|
|
public DateTime EndDate { get; set; }
|
|
}
|
|
|
|
public class DTONameFilter : DTODateFilter
|
|
{
|
|
public string Name { get; set; }
|
|
}
|
|
|
|
public class DTOPageAndFilterModel : DTONameFilter
|
|
{
|
|
public int PageSize;
|
|
public int Page;
|
|
}
|
|
/// <summary>
|
|
/// PIE CHART
|
|
/// </summary>
|
|
|
|
[XmlRoot("pieAndData")]
|
|
public class DTOReportData
|
|
{
|
|
[XmlElement("absoluteValue")]
|
|
public int AbsoluteValue { get; set; }
|
|
|
|
[XmlElement("productedPieces")]
|
|
public int ProductedPieces { get; set; }
|
|
|
|
[XmlElement("discardedPieces")]
|
|
public int DiscardedPieces { get; set; }
|
|
}
|
|
|
|
[XmlRoot("pieAndData")]
|
|
public class DTOPieChart
|
|
{
|
|
[XmlElement("stop")]
|
|
public int Stop { get; set; }
|
|
|
|
[XmlElement("run")]
|
|
public int Run { get; set; }
|
|
|
|
[XmlElement("idle")]
|
|
public int Idle { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// TIMELINE
|
|
/// </summary>
|
|
|
|
[XmlRoot("timeline")]
|
|
public class DTOTimeline
|
|
{
|
|
[XmlArray("partPrgs")]
|
|
[XmlArrayItem("partPrg", typeof(DTOTimelinePartPrg))]
|
|
public List<DTOTimelinePartPrg> PartPrgs { get; set; }
|
|
|
|
[XmlElement("statusData")]
|
|
public DTOTimelineData StatusData { get; set; }
|
|
}
|
|
|
|
public class DTOTimelineData
|
|
{
|
|
[XmlArray("runs")]
|
|
[XmlArrayItem("run", typeof(DTOTimelineDateElement))]
|
|
public List<DTOTimelineDateElement> Run { get; set; }
|
|
|
|
[XmlArray("idles")]
|
|
[XmlArrayItem("idle", typeof(DTOTimelineDateElement))]
|
|
public List<DTOTimelineDateElement> Idle { get; set; }
|
|
|
|
[XmlArray("stops")]
|
|
[XmlArrayItem("stop", typeof(DTOTimelineDateElement))]
|
|
public List<DTOTimelineDateElement> Stop { get; set; }
|
|
}
|
|
|
|
public class DTOTimelineDateElement
|
|
{
|
|
[XmlElement("from")]
|
|
public DateTime From { get; set; }
|
|
|
|
[XmlElement("to")]
|
|
public DateTime To { get; set; }
|
|
}
|
|
|
|
public class DTOTimelinePartPrg
|
|
{
|
|
[XmlElement("name")]
|
|
public string Name { get; set; }
|
|
|
|
[XmlElement("executed")]
|
|
public string Executed { get; set; }
|
|
|
|
[XmlElement("frequency")]
|
|
public string Frequency { get; set; }
|
|
|
|
[XmlArray("dates")]
|
|
[XmlArrayItem("date", typeof(DTOTimelineDateElement))]
|
|
public List<DTOTimelineDateElement> Occurrences { get; set; }
|
|
}
|
|
|
|
// Histogram
|
|
[XmlRoot("root")]
|
|
public class DTOHistogramModel
|
|
{
|
|
[XmlArray("programs")]
|
|
[XmlArrayItem("program", typeof(DTOHistogramItemModel))]
|
|
public List<DTOHistogramItemModel> Occurrences { get; set; }
|
|
|
|
public int Pages { get; set; }
|
|
}
|
|
|
|
public class DTOHistogramItemModel
|
|
{
|
|
[XmlElement("name")]
|
|
public string ProgName { get; set; }
|
|
|
|
[XmlElement("quantity")]
|
|
public int Quantity { get; set; }
|
|
|
|
[XmlElement("startDate")]
|
|
public string StartDate { get; set; }
|
|
|
|
[XmlElement("endDate")]
|
|
public string EndDate { get; set; }
|
|
|
|
[XmlElement("actualT")]
|
|
public string ActualT { get; set; }
|
|
|
|
[XmlElement("averageT")]
|
|
public string AverageT { get; set; }
|
|
|
|
[XmlElement("theoricT")]
|
|
public string TheoricT { get; set; }
|
|
|
|
[XmlElement("deviation")]
|
|
public string Deviation { get; set; }
|
|
|
|
[XmlElement("frequency")]
|
|
public int Frequency { get; set; }
|
|
}
|
|
}
|
|
} |