aboutsummaryrefslogtreecommitdiffstats
path: root/Software
diff options
context:
space:
mode:
authorRoy Ben Shabat <roy.mail.net@gmail.com>2025-09-10 03:02:56 +0300
committerRoy Ben Shabat <roy.mail.net@gmail.com>2025-09-10 03:02:56 +0300
commitb3f8ff791b0da2b600b719b745b99029b2df1c32 (patch)
tree309975ec47a0adacb9baf4a65bf6bdc02d09b11e /Software
parentba37d5082917551fd9a2b194fa1489f1fd86f39b (diff)
downloadTango-b3f8ff791b0da2b600b719b745b99029b2df1c32.tar.gz
Tango-b3f8ff791b0da2b600b719b745b99029b2df1c32.zip
Machine Studio: Added support for all inks and future inks.
Added failure reason. Implemented dynamic CSV Export.
Diffstat (limited to 'Software')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs263
-rw-r--r--Software/Visual_Studio/Tango.BL/Entities/JobRun.cs33
2 files changed, 117 insertions, 179 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
index 9327ecfdf..9637352f2 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
@@ -491,43 +491,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels
string jobName = SelectedJob == null ? "" : SelectedJob.Name;
- var db_JobRuns = db.JobRuns.Where(x => (x.StartDate <= endUtc && x.StartDate >= startUtc))
- .Select(x => new
- {
- x.ID,
- x.MachineType,
- x.ActualStartDate,
- x.EndDate,
- x.EndPosition,
- x.GradientResolutionCm,
- x.Guid,
- x.HeatingStartDate,
- x.IsGradient,
- x.JobGuid,
- x.JobLength,
- x.JobName,
- x.JobSource,
- x.MachineGuid,
- x.RmlGuid,
- x.StartDate,
- x.Status,
- x.UploadingStartDate,
- x.UserGuid,
- x.CyanQuantity,
- x.MagentaQuantity,
- x.YellowQuantity,
- x.BlackQuantity,
- x.TransparentQuantity,
- x.LubricantQuantity,
- x.CleanerQuantity,
- x.LightCyanQuantity,
- x.LightMagentaQuantity,
- x.LightYellowQuantity,
- x.IsHeadCleaning,
- x.ActualStartPosition,
- x.ActualEndPosition,
- x.JobLogicalLength,
- });
+ var db_JobRuns = db.JobRuns.Where(x => (x.StartDate <= endUtc && x.StartDate >= startUtc));
+
var machineIDs = new HashSet<string>(SelectedMachines.SynchedSource.ToList().Select(p => p.Guid));
if (machineIDs.Count > 0)
{
@@ -568,43 +533,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels
var runs_db = await db_JobRuns.ToListAsync(); //Execute actual query.
- List<JobRun> runs = runs_db.Where(x => (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))
- .Select(x => new JobRun()
- {
- ID = x.ID,
- MachineType = x.MachineType,
- ActualStartDate = x.ActualStartDate,
- EndDate = x.EndDate,
- EndPosition = x.EndPosition,
- GradientResolutionCm = x.GradientResolutionCm,
- Guid = x.Guid,
- HeatingStartDate = x.HeatingStartDate,
- IsGradient = x.IsGradient,
- JobGuid = x.JobGuid,
- JobLength = x.JobLength,
- JobName = x.JobName,
- JobSource = x.JobSource,
- MachineGuid = x.MachineGuid,
- RmlGuid = x.RmlGuid,
- StartDate = x.StartDate,
- Status = x.Status,
- UploadingStartDate = x.UploadingStartDate,
- UserGuid = x.UserGuid,
- CyanQuantity = x.CyanQuantity,
- MagentaQuantity = x.MagentaQuantity,
- YellowQuantity = x.YellowQuantity,
- BlackQuantity = x.BlackQuantity,
- TransparentQuantity = x.TransparentQuantity,
- LubricantQuantity = x.LubricantQuantity,
- CleanerQuantity = x.CleanerQuantity,
- LightCyanQuantity = x.LightCyanQuantity,
- LightMagentaQuantity = x.LightMagentaQuantity,
- LightYellowQuantity = x.LightYellowQuantity,
- IsHeadCleaning = x.IsHeadCleaning,
- ActualStartPosition = x.ActualStartPosition,
- ActualEndPosition = x.ActualEndPosition,
- JobLogicalLength = x.JobLogicalLength,
- }).ToList();
+ List<JobRun> runs = runs_db.Where(x => (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue)).ToList();
var modelList = runs.Select(x => new JobRunModel()
{
@@ -633,107 +562,108 @@ namespace Tango.MachineStudio.Statistics.ViewModels
private void ExportToExcel()
{
- SaveFileDialog dlg = new SaveFileDialog();
- dlg.Title = "Job Runs Statistic Report";
- dlg.Filter = "CSV Files|*.csv";
- dlg.FileName = $"Statistics_Job_runs";
- dlg.DefaultExt = ".csv";
- if (dlg.ShowDialog().Value)
+ SaveFileDialog dlg = new SaveFileDialog
+ {
+ Title = "Job Runs Statistic Report",
+ Filter = "CSV Files|*.csv",
+ FileName = "Statistics_Job_runs",
+ DefaultExt = ".csv"
+ };
+
+ if (dlg.ShowDialog().GetValueOrDefault())
{
try
{
- CsvFile<ExcelModel> csvFile = new CsvFile<ExcelModel>(new CsvDestination(dlg.FileName), new CsvDefinition()
+ var csv = new CsvDynamicWriter();
+
+ // ===== Fixed column indices (preserve your original order before outputs) =====
+ const int IDX_ID = 0;
+ const int IDX_Gen = 1;
+ const int IDX_Machine = 2;
+ const int IDX_Source = 3;
+ const int IDX_JobName = 4;
+ const int IDX_JobKind = 5;
+ const int IDX_Thread = 6;
+ const int IDX_Length = 7;
+ const int IDX_NumberOfUnits = 8;
+ const int IDX_StartTime = 9;
+ const int IDX_Duration = 10;
+ const int IDX_Distance = 11;
+ const int IDX_StartPosition = 12;
+ const int IDX_EndPosition = 13;
+ const int IDX_Status = 14;
+
+ // ===== Dynamic outputs start here; one slot per enum value in stable order =====
+ var liquids = (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes));
+ const int OUTPUT_BASE = 15;
+
+ // "Failure Reason" will appear AFTER all potential output columns
+ int IDX_FailureReason = OUTPUT_BASE + liquids.Length;
+
+ // Optional: header name normalization for specific liquids (keeps your legacy "Transparent Ink" name)
+ Func<LiquidTypes, string> outputHeader = lt =>
{
- Columns = new List<String>()
- {
- "ID",
- "Gen",
- "Machine",
- "Source",
- "Job Name",
- "Job Kind",
- "Thread",
- "Length",
- "Number Of Units",
- "Start Time",
- "Duration",
- "Distance",
- "Start Position",
- "End Position",
- "Status",
- "Output Cyan",
- "Output Magenta",
- "Output Yellow",
- "Output Black",
- "Output Light Cyan",
- "Output Light Magenta",
- "Output Light Yellow",
- "Output Blue",
- "Output Light Blue",
- "Output Orange",
- "Output Light Orange",
- "Output Rubine",
- "Output Light Rubine",
- "Output Navy",
- "Output Violet",
- "Output Transparent Ink",
- "Output Lubricant",
- "Failure Reason",
- },
- });
- var selection = JobRuns;// item 5861 (all available jobs should be saved) .Where(z => z.JobRun.EndPosition > 0 && z.JobRun.EndDate != null && z.JobRun.ActualStartDate != null);
+ return "Output " + lt; // e.g., "Output Cyan", "Output LightCyan", "Output Lubricant"
+ };
+
+ var selection = JobRuns;
foreach (var jobRunModel in selection)
{
- ExcelModel excel_model = new ExcelModel();
- excel_model.ID = jobRunModel.JobRun.ID.ToString();
- excel_model.Gen = ((MachineTypes)jobRunModel.JobRun.MachineType).ToShortName();
- excel_model.Machine = jobRunModel.Machine != null ? jobRunModel.Machine.SerialNumber : "";
- excel_model.Source = jobRunModel.JobRun.Source.ToString();
- excel_model.JobName = jobRunModel.JobRun.JobName;
- excel_model.JobKind = ((JobDesignations)jobRunModel.JobRun.JobDesignation).ToDescription();
- excel_model.Thread = jobRunModel.Rml != null ? jobRunModel.Rml.Name : "";
- excel_model.Length = jobRunModel.LogicalLengthMeters.ToString();
- excel_model.NumberOfUnits = Math.Max(jobRunModel.JobRun.NumberOfUnits, 1).ToString();
- excel_model.StartTime = jobRunModel.JobRun.StartDate.ToLocalTime().ToString();
- //excel_model.UploadDuration = jobRunModel.UploadDuration != null ? ((TimeSpan)(jobRunModel.UploadDuration)).ToString(@"hh\:mm\:ss") : TimeSpan.FromSeconds(0).ToString(@"hh\:mm\:ss");
- //excel_model.HeatingDuration = jobRunModel.HeatingDuration != null ? ((TimeSpan)(jobRunModel.HeatingDuration)).ToString(@"hh\:mm\:ss") : TimeSpan.FromSeconds(0).ToString(@"hh\:mm\:ss");
- //excel_model.IsGradient = jobRunModel.JobRun.IsGradient ? "Yes" : "No";
- //excel_model.GR = jobRunModel.JobRun.GradientResolutionCm.ToString();
- excel_model.Duration = jobRunModel.Duration.ToStringUnlimitedHours();
- excel_model.Distance = jobRunModel.Distance.ToString();
- excel_model.StartPosition = jobRunModel.ActualStartPosition.ToString();
- excel_model.EndPosition = jobRunModel.ActualEndPosition.ToString();
- excel_model.Status = jobRunModel.JobRun.JobRunStatus.ToString();
- //excel_model.EndTime = jobRunModel.JobRun.EndDate != null ? ((DateTime)jobRunModel.JobRun.EndDate).ToLocalTime().ToString("MM/dd/yy HH:mm"): "";
- //excel_model.TotalDyeingTime = jobRunModel.JobRun.TotalDyeingTime != default(TimeSpan) ? ((TimeSpan)jobRunModel.JobRun.TotalDyeingTime).ToString(@"hh\:mm\:ss") : TimeSpan.FromSeconds(0).ToString(@"hh\:mm\:ss");
+ // ===== Fixed fields =====
+ csv.Write(jobRunModel.JobRun.ID.ToString(), "ID", "", IDX_ID);
+ csv.Write(((MachineTypes)jobRunModel.JobRun.MachineType).ToShortName(), "Gen", "", IDX_Gen);
+ csv.Write(jobRunModel.Machine != null ? jobRunModel.Machine.SerialNumber : "",
+ "Machine", "", IDX_Machine);
+ csv.Write(jobRunModel.JobRun.Source.ToString(), "Source", "", IDX_Source);
+ csv.Write(jobRunModel.JobRun.JobName, "Job Name", "", IDX_JobName);
+ csv.Write(((JobDesignations)jobRunModel.JobRun.JobDesignation).ToDescription(),
+ "Job Kind", "", IDX_JobKind);
+ csv.Write(jobRunModel.Rml != null ? jobRunModel.Rml.Name : "", "Thread", "", IDX_Thread);
+ csv.Write(jobRunModel.LogicalLengthMeters.ToString(), "Length", "0", IDX_Length);
+ csv.Write(Math.Max(jobRunModel.JobRun.NumberOfUnits, 1).ToString(), "Number Of Units", "0", IDX_NumberOfUnits);
+ csv.Write(jobRunModel.JobRun.StartDate.ToLocalTime().ToString(), "Start Time", "", IDX_StartTime);
+ csv.Write(jobRunModel.Duration.ToStringUnlimitedHours(), "Duration", "", IDX_Duration);
+ csv.Write(jobRunModel.Distance.ToString(), "Distance", "0", IDX_Distance);
+ csv.Write(jobRunModel.ActualStartPosition.ToString(), "Start Position", "0", IDX_StartPosition);
+ csv.Write(jobRunModel.ActualEndPosition.ToString(), "End Position", "0", IDX_EndPosition);
+ csv.Write(jobRunModel.JobRun.JobRunStatus.ToString(), "Status", "", IDX_Status);
- excel_model.OutputCyan = jobRunModel.JobRun.CyanQuantity < 0 ? "" : jobRunModel.JobRun.CyanQuantity.ToString();
- excel_model.OutputMagenta = jobRunModel.JobRun.MagentaQuantity < 0 ? "" : jobRunModel.JobRun.MagentaQuantity.ToString();
- excel_model.OutputYellow = jobRunModel.JobRun.YellowQuantity < 0 ? "" : jobRunModel.JobRun.YellowQuantity.ToString();
- excel_model.OutputBlack = jobRunModel.JobRun.BlackQuantity < 0 ? "" : jobRunModel.JobRun.BlackQuantity.ToString();
- excel_model.OutputLightCyan = jobRunModel.JobRun.LightCyanQuantity < 0 ? "" : jobRunModel.JobRun.LightCyanQuantity.ToString();
- excel_model.OutputLightMagenta = jobRunModel.JobRun.LightMagentaQuantity < 0 ? "" : jobRunModel.JobRun.LightMagentaQuantity.ToString();
- excel_model.OutputLightYellow = jobRunModel.JobRun.LightYellowQuantity < 0 ? "" : jobRunModel.JobRun.LightYellowQuantity.ToString();
+ // ===== Dynamic Outputs (only write columns with value > 0) =====
+ // Use reflection to read {Liquid}Quantity from jobRunModel.JobRun, case-insensitive.
+ var jr = jobRunModel.JobRun;
+ var qtyProps = jr.GetType()
+ .GetProperties()
+ .Where(p => p.Name.EndsWith("Quantity", StringComparison.OrdinalIgnoreCase))
+ .ToDictionary(p => p.Name.ToLowerInvariant());
- excel_model.OutputBlue = jobRunModel.JobRun.BlueQuantity < 0 ? "" : jobRunModel.JobRun.BlueQuantity.ToString();
- excel_model.OutputLightBlue = jobRunModel.JobRun.LightBlueQuantity < 0 ? "" : jobRunModel.JobRun.LightBlueQuantity.ToString();
- excel_model.OutputOrange = jobRunModel.JobRun.OrangeQuantity < 0 ? "" : jobRunModel.JobRun.OrangeQuantity.ToString();
- excel_model.OutputLightOrange = jobRunModel.JobRun.LightOrangeQuantity < 0 ? "" : jobRunModel.JobRun.LightOrangeQuantity.ToString();
- excel_model.OutputRubine = jobRunModel.JobRun.RubineQuantity < 0 ? "" : jobRunModel.JobRun.RubineQuantity.ToString();
- excel_model.OutputLightRubine = jobRunModel.JobRun.LightRubineQuantity < 0 ? "" : jobRunModel.JobRun.LightRubineQuantity.ToString();
- excel_model.OutputNavy = jobRunModel.JobRun.NavyQuantity < 0 ? "" : jobRunModel.JobRun.NavyQuantity.ToString();
- excel_model.OutputViolet = jobRunModel.JobRun.VioletQuantity < 0 ? "" : jobRunModel.JobRun.VioletQuantity.ToString();
+ for (int i = 0; i < liquids.Length; i++)
+ {
+ var lt = liquids[i];
+ var propKey = (lt.ToString() + "Quantity").ToLowerInvariant();
+ if (qtyProps.TryGetValue(propKey, out var pi))
+ {
+ var obj = pi.GetValue(jr);
+ double val = 0;
+ if (obj != null)
+ {
+ try { val = Convert.ToDouble(obj); } catch { val = 0; }
+ }
- excel_model.OutputTransparent = jobRunModel.JobRun.TransparentQuantity < 0 ? "" : jobRunModel.JobRun.TransparentQuantity.ToString();
- excel_model.OutputLubricant = jobRunModel.JobRun.LubricantQuantity < 0 ? "" : jobRunModel.JobRun.LubricantQuantity.ToString();
- //excel_model.Cleaner = jobRunModel.JobRun.CleanerQuantity < 0 ? "" : jobRunModel.JobRun.CleanerQuantity.ToString();
- excel_model.FailureReason = jobRunModel.JobRun.FailedMessage;
+ if (val > 0)
+ {
+ var col = outputHeader(lt);
+ csv.Write(val.ToString(), col, "0", OUTPUT_BASE + i);
+ }
+ }
+ }
- csvFile.Append(excel_model);
+ // ===== Failure reason (last) =====
+ csv.Write(jobRunModel.JobRun.FailedMessage, "Failure Reason", "", IDX_FailureReason);
+ csv.Next();
}
- csvFile.Dispose();
+ csv.Save(dlg.FileName);
_notification.ShowInfo("Report generated successfully.");
}
catch (Exception ex)
@@ -744,6 +674,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels
}
}
+
#region GenerateS_StatisticsValueCollection
/// <summary>
@@ -888,14 +819,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels
Quantity = x.Value
}).ToList();
+ allLiquidQuantities = allLiquidQuantities.Where(x => x.Quantity > 0).ToList();
- //foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes)))
- //{
- // var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.FirstOrDefault(y => y.LiquidType == ltype)).Where(x => x != null);
- // var count = liquidQuantityByTypeList != null ? liquidQuantityByTypeList.Sum(x => x.Quantity) : 0;
- // JobRunLiquidQuantity lq = new JobRunLiquidQuantity() { LiquidType = ltype, Quantity = count };
- // allLiquidQuantities.Add(lq);
- //}
StatisticsValueCollection.GenerateStatisticsLiquidQuantity(allLiquidQuantities);
}
#endregion
diff --git a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs
index f2a182e84..d98c384ce 100644
--- a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs
+++ b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs
@@ -95,16 +95,29 @@ namespace Tango.BL.Entities
{
_liquidQuantitiesFast = new List<JobRunLiquidQuantity>();
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Cyan, Quantity = CyanQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Magenta, Quantity = MagentaQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Yellow, Quantity = YellowQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Black, Quantity = BlackQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Transparent, Quantity = TransparentQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Lubricant, Quantity = LubricantQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.Cleaner, Quantity = CleanerQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.LightCyan, Quantity = LightCyanQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.LightMagenta, Quantity = LightMagentaQuantity });
- _liquidQuantitiesFast.Add(new JobRunLiquidQuantity() { LiquidType = LiquidTypes.LightYellow, Quantity = LightYellowQuantity });
+ // Cache all properties once for faster lookup
+ var props = this.GetType()
+ .GetProperties()
+ .Where(p => p.Name.EndsWith("Quantity", StringComparison.OrdinalIgnoreCase))
+ .ToDictionary(p => p.Name.ToLowerInvariant());
+
+ foreach (LiquidTypes lt in Enum.GetValues(typeof(LiquidTypes)))
+ {
+ string expectedPropName = (lt.ToString() + "Quantity").ToLowerInvariant();
+
+ if (props.TryGetValue(expectedPropName, out var prop))
+ {
+ var value = prop.GetValue(this);
+ if (value != null)
+ {
+ _liquidQuantitiesFast.Add(new JobRunLiquidQuantity()
+ {
+ LiquidType = lt,
+ Quantity = Convert.ToInt64(value)
+ });
+ }
+ }
+ }
}
return _liquidQuantitiesFast;