Leaf Chart streamline
This commit is contained in:
@@ -73,7 +73,7 @@ namespace LeafWeb.Core.DAL
|
|||||||
{
|
{
|
||||||
return _db.LeafInputFiles.Find(id);
|
return _db.LeafInputFiles.Find(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<LeafInputFile> GetLeafInputFiles(LeafInputStatusType status)
|
public IQueryable<LeafInputFile> GetLeafInputFiles(LeafInputStatusType status)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -10,5 +10,8 @@ namespace LeafWeb.Core.Entities
|
|||||||
public string Filename { get; set; }
|
public string Filename { get; set; }
|
||||||
|
|
||||||
public byte[] Contents { get; set; }
|
public byte[] Contents { get; set; }
|
||||||
|
|
||||||
|
// convention for the filename which LeafCharter uses
|
||||||
|
public bool IsLeafChartFile => Filename?.StartsWith("cntrlcomparison") ?? false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,30 +16,47 @@ namespace LeafWeb.Web.Controllers
|
|||||||
{
|
{
|
||||||
public ActionResult Index(int leafInputFileId)
|
public ActionResult Index(int leafInputFileId)
|
||||||
{
|
{
|
||||||
|
var hasLeafOutputFile =
|
||||||
|
DataService
|
||||||
|
.GetLeafInputFile(leafInputFileId)?
|
||||||
|
.LeafOutputFiles?
|
||||||
|
.FirstOrDefault(f => f.IsLeafChartFile) != null;
|
||||||
|
|
||||||
return View(leafInputFileId);
|
return View(leafInputFileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult LeafCharts(int leafInputFileId, int number)
|
public ActionResult LeafCharts(int leafInputFileId, int number)
|
||||||
{
|
{
|
||||||
var leafInputFile = DataService.GetLeafInputFile(leafInputFileId);
|
var leafOutputFile =
|
||||||
var leafOutputFile = leafInputFile.LeafOutputFiles.FirstOrDefault(f => f.Filename.StartsWith("cntrlcomparison"));
|
DataService
|
||||||
//if (leafOutputFile == null)
|
.GetLeafInputFile(leafInputFileId)?
|
||||||
// return View(); // TODO: break
|
.LeafOutputFiles?
|
||||||
|
.FirstOrDefault(f => f.IsLeafChartFile);
|
||||||
|
|
||||||
CntrlComparison[] cntrlComparison;
|
if (leafOutputFile == null)
|
||||||
using (var parser = new CntrlComparisonParser(leafOutputFile.Contents))
|
return View(); // TODO: break
|
||||||
|
|
||||||
|
return File(GetChartImage(leafOutputFile.Contents, number), "image/png", "mychart.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] GetChartImage(byte[] fileContents, int number, ChartImageFormat format = ChartImageFormat.Png)
|
||||||
|
{
|
||||||
|
CntrlComparison[] cntrlComparison;
|
||||||
|
using (var parser = new CntrlComparisonParser(fileContents))
|
||||||
cntrlComparison = parser.Parse();
|
cntrlComparison = parser.Parse();
|
||||||
|
|
||||||
var curveData = CurveDataConverter.Convert(cntrlComparison).ToArray();
|
var curveData = CurveDataConverter.Convert(cntrlComparison).ToArray();
|
||||||
|
|
||||||
var charts = LeafWebCharter.ProduceCharts(curveData[2]);
|
var charts = LeafWebCharter.ProduceCharts(curveData[2]);
|
||||||
|
|
||||||
using (var ms = new MemoryStream())
|
//Image.FromFile()
|
||||||
|
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
charts.Skip(number).First().SaveImage(ms, ChartImageFormat.Png);
|
charts.Skip(number).First().SaveImage(ms, format);
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
return File(ms.ToArray(), "image/png", "mychart.png");
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace LeafWeb.Web.ViewModels.LeafOutput
|
|||||||
public string CurrentStatus { get; set; }
|
public string CurrentStatus { get; set; }
|
||||||
public string[] ErrorMessages { get; set; }
|
public string[] ErrorMessages { get; set; }
|
||||||
public string[] LeafOutputFilenames { get; set; }
|
public string[] LeafOutputFilenames { get; set; }
|
||||||
|
public bool HasLeafChartOutputFile { get; set; }
|
||||||
public string LeafInputName { get; set; }
|
public string LeafInputName { get; set; }
|
||||||
public string LeafInputIdentifier { get; set; }
|
public string LeafInputIdentifier { get; set; }
|
||||||
public string LeafInputSiteId { get; set; }
|
public string LeafInputSiteId { get; set; }
|
||||||
@@ -33,6 +34,9 @@ namespace LeafWeb.Web.ViewModels.LeafOutput
|
|||||||
.Select(o => o.Filename)
|
.Select(o => o.Filename)
|
||||||
.ToArray()
|
.ToArray()
|
||||||
?? new string[] {}))
|
?? new string[] {}))
|
||||||
|
.ForMember(dest => dest.HasLeafChartOutputFile,
|
||||||
|
opt => opt.ResolveUsing(
|
||||||
|
file => file.LeafOutputFiles?.Any(o => o.IsLeafChartFile)))
|
||||||
.ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.LeafInput.Name))
|
.ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.LeafInput.Name))
|
||||||
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.LeafInput.Identifier))
|
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.LeafInput.Identifier))
|
||||||
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.LeafInput.SiteId))
|
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.LeafInput.SiteId))
|
||||||
|
|||||||
Reference in New Issue
Block a user