Skip to content

Commit

Permalink
4.3 - Fix some issues with reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Liedke, Daniel committed Jun 16, 2024
1 parent 9c6c254 commit a30ba21
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
27 changes: 15 additions & 12 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public partial class MainForm : Form
bool _hideToolTipTimer = false;
private ToolTipForm _toolTipForm = new ToolTipForm();

private int _totalBreaksTime;
private int _totalBreakTime;
private int _totalMeetingTime;
private int _totalLunchTime;
private int _totalLongBreakTime;
private int _totalBreaksCount;
private Label lblText;
private int _totalTasksTime;
private int _totalTaskTime;
private System.Drawing.Size _originalToolTipFormSize;

private TimerStatus _previousStatus = TimerStatus.Task;
Expand Down Expand Up @@ -200,10 +200,10 @@ private void Timer_Tick(object sender, EventArgs e)
switch (_currentStatus)
{
case TimerStatus.Task:
_totalTasksTime++;
_totalTaskTime++;
break;
case TimerStatus.Break:
_totalBreaksTime++;
_totalBreakTime++;
break;
case TimerStatus.Meeting:
_totalMeetingTime++;
Expand Down Expand Up @@ -397,23 +397,26 @@ private void UpdateFullScreenStatus()
private void UpdateTotalTimes()
{
// Update Break/Task/Meeting/Total times
totalBreaksTimeToolStripMenuItem.Text = $"Total Break Time: {TimeSpan.FromSeconds(_totalBreaksTime):hh\\:mm\\:ss}";
totalTasksTimeToolStripMenuItem.Text = $"Total Task Time: {TimeSpan.FromSeconds(_totalTasksTime):hh\\:mm\\:ss}";
totalBreaksTimeToolStripMenuItem.Text = $"Total Break Time: {TimeSpan.FromSeconds(_totalBreakTime):hh\\:mm\\:ss}";
totalTasksTimeToolStripMenuItem.Text = $"Total Task Time: {TimeSpan.FromSeconds(_totalTaskTime):hh\\:mm\\:ss}";
totalMeetingTimeToolStripMenuItem.Text = $"Total Meeting Time: {TimeSpan.FromSeconds(_totalMeetingTime):hh\\:mm\\:ss}";
totalLunchTimeToolStripMenuItem.Text = $"Total Lunch Time: {TimeSpan.FromSeconds(_totalLunchTime):hh\\:mm\\:ss}";
totalLongBreakTimeToolStripMenuItem.Text = $"Total Long Break Time: {TimeSpan.FromSeconds(_totalLongBreakTime):hh\\:mm\\:ss}";

// Calculate total work time (task + meeting)
int totalWorkTime = _totalTasksTime + _totalMeetingTime;
int totalWorkTime = _totalTaskTime + _totalMeetingTime;
totalWorkTimeToolStripMenuItem.Text = $"Total Work Time: {TimeSpan.FromSeconds(totalWorkTime):hh\\:mm\\:ss}";

// Calculate total rest time (break + long break + lunch)
int totalRestTime = _totalBreaksTime + _totalLongBreakTime + _totalLunchTime;
int totalRestTime = _totalBreakTime + _totalLongBreakTime + _totalLunchTime;
totalRestTimeToolStripMenuItem.Text = $"Total Rest Time: {TimeSpan.FromSeconds(totalRestTime):hh\\:mm\\:ss}";

totalTimeToolStripMenuItem.Text = $"Total Time Today: {TimeSpan.FromSeconds(_totalBreaksTime + _totalTasksTime + _totalMeetingTime):hh\\:mm\\:ss}";
// Calculate total time today (work + rest)
int totalTime = totalWorkTime + totalRestTime;
totalTimeToolStripMenuItem.Text = $"Total Time Today: {TimeSpan.FromSeconds(totalTime):hh\\:mm\\:ss}";

totalBreaksCountToolStripMenuItem.Text = $"Total Breaks: {_totalBreaksCount}";
// Update total breaks count
totalBreaksCountToolStripMenuItem.Text = $"Total Breaks Today: {_totalBreaksCount}";
}

#endregion
Expand Down Expand Up @@ -777,12 +780,12 @@ private void SaveSettings()

private void SaveMetrics()
{
MetricsReportManager.SaveMetricsReport(DateTime.Today, _totalTasksTime, _totalMeetingTime, _totalBreaksTime, _totalLunchTime, _totalLongBreakTime, _totalLunchTime, _totalBreaksCount);
MetricsReportManager.SaveMetricsReport(DateTime.Today, _totalTaskTime, _totalMeetingTime, _totalBreakTime, _totalLongBreakTime, _totalLunchTime, _totalBreaksCount);
}

private void LoadMetrics()
{
(_totalTasksTime, _totalMeetingTime, _totalBreaksTime, _totalLunchTime, _totalLongBreakTime, _totalLunchTime, _totalBreaksCount, _) = MetricsReportManager.LoadMetricsReport(DateTime.Today);
(_totalTaskTime, _totalMeetingTime, _totalBreakTime, _totalLongBreakTime, _totalLunchTime, _totalBreaksCount, _) = MetricsReportManager.LoadMetricsReport(DateTime.Today);
}

#endregion
Expand Down
27 changes: 14 additions & 13 deletions MetricsReportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ public class MetricsReportManager
{
private static string ReportFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "pomodoro_timer_report.csv");

public static void SaveMetricsReport(DateTime date, int totalTasksTime, int totalMeetingTime, int totalBreaksTime, int totalLaunchTime, int totalLongBreakTime, int totalLunchTime, int totalBreaksCount)
public static void SaveMetricsReport(DateTime date, int totalTasksTime, int totalMeetingTime, int totalBreaksTime, int totalLongBreakTime, int totalLunchTime, int totalBreaksCount)
{
int totalTime = totalTasksTime + totalMeetingTime + totalBreaksTime + totalLaunchTime + totalLongBreakTime + totalLunchTime;
int totalWorkTime = totalTasksTime + totalMeetingTime;
int totalRestTime = totalBreaksTime + totalLongBreakTime + totalLunchTime;
int totalTime = totalWorkTime + totalRestTime;

string reportLine = $"{date.ToString("yyyy-MM-dd")},{totalTasksTime},{totalMeetingTime},{totalBreaksTime},{totalLaunchTime},{totalLongBreakTime},{totalLunchTime},{totalBreaksCount},{totalTime},{FormatTime(totalTasksTime)},{FormatTime(totalMeetingTime)},{FormatTime(totalBreaksTime)},{FormatTime(totalLaunchTime)},{FormatTime(totalLongBreakTime)},{FormatTime(totalLunchTime)},{FormatTime(totalTime)}";
string reportLine = $"{date.ToString("yyyy-MM-dd")},{totalTasksTime},{totalMeetingTime},{totalBreaksTime},{totalLongBreakTime},{totalLunchTime},{totalBreaksCount},{totalWorkTime},{totalRestTime},{totalTime},{FormatTime(totalTasksTime)},{FormatTime(totalMeetingTime)},{FormatTime(totalBreaksTime)},{FormatTime(totalLongBreakTime)},{FormatTime(totalLunchTime)},{FormatTime(totalWorkTime)},{FormatTime(totalRestTime)},{FormatTime(totalTime)}";

// Add header row if the file doesn't exist
if (!File.Exists(ReportFilePath))
{
string headerRow = "Date,Total Task Seconds,Total Meeting Seconds,Total Break Seconds,Total Launch Seconds,Total Long Break Seconds,Total Lunch Seconds,Total Breaks Count,Total Seconds,Total Task Time,Total Meeting Time,Total Break Time,Total Launch Time,Total Long Break Time,Total Lunch Time,Total Time";
string headerRow = "Date,Total Task Seconds,Total Meeting Seconds,Total Break Seconds,Total Long Break Seconds,Total Lunch Seconds,Total Breaks Count,Total Work Seconds,Total Rest Seconds,Total Seconds,Total Task Time,Total Meeting Time,Total Break Time,Total Long Break Time,Total Lunch Time,Total Work Time,Total Rest Time,Total Time";
File.WriteAllText(ReportFilePath, headerRow + Environment.NewLine);
}

Expand Down Expand Up @@ -45,7 +47,7 @@ public static void SaveMetricsReport(DateTime date, int totalTasksTime, int tota
}
}

public static (int totalTasksTime, int totalMeetingTime, int totalBreaksTime, int totalLaunchTime, int totalLongBreakTime, int totalLunchTime, int totalBreaksCount, int totalTime) LoadMetricsReport(DateTime date)
public static (int totalTasksTime, int totalMeetingTime, int totalBreaksTime, int totalLongBreakTime, int totalLunchTime, int totalBreaksCount, int totalTime) LoadMetricsReport(DateTime date)
{
if (File.Exists(ReportFilePath))
{
Expand All @@ -56,22 +58,21 @@ public static (int totalTasksTime, int totalMeetingTime, int totalBreaksTime, in
if (!string.IsNullOrEmpty(reportLine))
{
string[] values = reportLine.Split(',');
if (values.Length == 16 &&
if (values.Length == 18 &&
int.TryParse(values[1], out int totalTasksTime) &&
int.TryParse(values[2], out int totalMeetingTime) &&
int.TryParse(values[3], out int totalBreaksTime) &&
int.TryParse(values[4], out int totalLaunchTime) &&
int.TryParse(values[5], out int totalLongBreakTime) &&
int.TryParse(values[6], out int totalLunchTime) &&
int.TryParse(values[7], out int totalBreaksCount) &&
int.TryParse(values[8], out int totalTime))
int.TryParse(values[4], out int totalLongBreakTime) &&
int.TryParse(values[5], out int totalLunchTime) &&
int.TryParse(values[6], out int totalBreaksCount) &&
int.TryParse(values[9], out int totalTime))
{
return (totalTasksTime, totalMeetingTime, totalBreaksTime, totalLaunchTime, totalLongBreakTime, totalLunchTime, totalBreaksCount, totalTime);
return (totalTasksTime, totalMeetingTime, totalBreaksTime, totalLongBreakTime, totalLunchTime, totalBreaksCount, totalTime);
}
}
}

return (0, 0, 0, 0, 0, 0, 0, 0);
return (0, 0, 0, 0, 0, 0, 0);
}

private static string FormatTime(int totalSeconds)
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyFileVersion("4.2.0.0")]
[assembly: AssemblyVersion("4.3.0.0")]
[assembly: AssemblyFileVersion("4.3.0.0")]

0 comments on commit a30ba21

Please sign in to comment.