Skip to content

Commit

Permalink
Added TimeGraphView
Browse files Browse the repository at this point in the history
In this version a Timegraph can be drawn in a view.  This completes toe functional additions for the first release.

A number of small bugs is fiexed, mainly regaring null references and other stupid errors.
The  LoggingView screeen now works properly. You can filter and all logging events are properly displayed. There still is one issue to fix, if the logging window is not active, no logging is written.
  • Loading branch information
RudolfJan committed Apr 27, 2020
1 parent f0d1549 commit 7a189b5
Show file tree
Hide file tree
Showing 16 changed files with 702 additions and 55 deletions.
1 change: 1 addition & 0 deletions DataAccess.Library/SQL/CreateFullTimeEvents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AS SELECT
,Locations.[Order] AS LocationOrder
,TimeEvents.EventType AS EventType
,TimeEvents.ArrivalTime AS ArrivalTime
,TimeEvents.WaitTime AS WaitTime
,TimeEvents.[Order] AS [Order]
,Services.ServiceAbbreviation AS ServiceAbbreviation
,Services.ServiceName AS ServiceName
Expand Down
2 changes: 1 addition & 1 deletion TimeTableTool.Desktop/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TimetableTool.Desktop
{
public class Bootstrapper : BootstrapperBase
{
private SimpleContainer _container = new SimpleContainer();
private readonly SimpleContainer _container = new SimpleContainer();

public Bootstrapper()
{
Expand Down
8 changes: 4 additions & 4 deletions TimeTableTool.Desktop/ViewModels/ServiceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public bool HasTimeEvents
}

private BindableCollection<FullTimeEventModel> _fullTimeEventsList;

public BindableCollection<FullTimeEventModel> FullTimeEventsList
{
get
Expand All @@ -47,7 +46,6 @@ public BindableCollection<FullTimeEventModel> FullTimeEventsList
}
}


private ServiceModel _selectedService;
private ServiceDirectionModel _selectedServiceDirection;
private string _serviceName;
Expand Down Expand Up @@ -283,8 +281,7 @@ public void SaveService()
}
ClearService();
ServicesUI.ServiceList = new BindableCollection<ServiceModel>(ServiceDataAccess.GetServicesPerRoute(RouteId));
NotifyOfPropertyChange(() => ServicesUI);
NotifyOfPropertyChange(()=>CanLoadTimeEvents);

}

public void ClearService()
Expand All @@ -297,6 +294,9 @@ public void ClearService()
ServiceDirectionId = 0;
ServiceDirectionName = "";
ServiceId = 0;
NotifyOfPropertyChange(() => ServicesUI);
NotifyOfPropertyChange(()=>CanLoadTimeEvents);
NotifyOfPropertyChange(() => CanEditService);
}

public bool CanLoadTimeEvents
Expand Down
10 changes: 9 additions & 1 deletion TimeTableTool.Desktop/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,19 @@ public TimetableModel SelectedTimetable
set
{
_selectedTimetable = value;
// Note for some timetable displays it is assumed they are unidirectional. Therefore we use two conditions here to enable the views.
IsTimetableSelected= SelectedTimetable != null && SelectedTimetable.IsMultiDirection==false;
IsTimetableSelectedMultiDirection = SelectedTimetable != null;
NotifyOfPropertyChange(() => SelectedTimetable);
NotifyOfPropertyChange(() => IsEditServiceInstancesEnabled);
NotifyOfPropertyChange(()=>IsTimetableSelected);
NotifyOfPropertyChange(()=>IsTimetableSelectedMultiDirection);
}
}

public bool IsTimetableSelected { get; set; }
public bool IsTimetableSelectedMultiDirection { get; set; }

public SaveFileModel SaveFileParams { get; set; } = new SaveFileModel();

public ShellViewModel(IEventAggregator events, IWindowManager windowManager)
Expand Down Expand Up @@ -142,7 +150,7 @@ public async Task ViewTimetable()

public async Task ViewGraph()
{
var displayTimetableGraphVM = IoC.Get<DisplayTimeTableGraphViewModel>();
var displayTimetableGraphVM = IoC.Get<DisplayTimetableGraphViewModel>();
displayTimetableGraphVM.TimetableId = SelectedTimetable.Id;
await ActivateItemAsync(displayTimetableGraphVM, new CancellationToken());

Expand Down
26 changes: 22 additions & 4 deletions TimeTableTool.Desktop/ViewModels/TimeTableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,20 @@ public void EditTimetable()
TimetableAbbreviation = SelectedTimetable.TimetableAbbreviation;
TimetableDescription = SelectedTimetable.TimetableDescription;
TimetableId = SelectedTimetable.Id;
ServiceDirectionId = SelectedTimetable.Id;
ServiceDirection = ServiceDirectionDataAccess.GetServiceDirectionById(ServiceDirectionId);
ServiceDirectionName = ServiceDirection.ServiceDirectionName;
IsMultiDirection = SelectedTimetable.IsMultiDirection;
if (IsMultiDirection)
{
ServiceDirectionId = -1;
ServiceDirection = null;
ServiceDirectionName = "";
}
else
{
ServiceDirectionId = SelectedTimetable.ServiceDirectionId;
ServiceDirection = ServiceDirectionDataAccess.GetServiceDirectionById(ServiceDirectionId);
ServiceDirectionName = ServiceDirection.ServiceDirectionName;
}

}

public bool CanDeleteTimetable
Expand Down Expand Up @@ -327,7 +337,14 @@ public void SaveTimetable()
newTimetable.TimetableAbbreviation = TimetableAbbreviation;
newTimetable.RouteId = RouteId;
newTimetable.IsMultiDirection = IsMultiDirection;
newTimetable.ServiceDirectionId = ServiceDirectionId;
if (IsMultiDirection)
{
newTimetable.ServiceDirectionId = -1;
}
else
{
newTimetable.ServiceDirectionId = ServiceDirectionId;
}
if (TimetableId <= 0)
{
TimetableDataAccess.InsertTimetableForRoute(newTimetable);
Expand All @@ -348,6 +365,7 @@ public void ClearTimetable()
TimetableAbbreviation = "";
TimetableName = "";
TimetableId = 0;
IsMultiDirection = false;
ServiceDirectionName = "";
ServiceDirectionId = 0;
ServiceDirection = null;
Expand Down
6 changes: 3 additions & 3 deletions TimeTableTool.Desktop/Views/ShellView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<DockPanel>
<Menu x:Name="Menu" DockPanel.Dock="Top" FontSize="12">
<MenuItem x:Name="FileMenu" Header="_File">
<MenuItem x:Name="ExportTimetable" Header="E_xport ..." IsEnabled="{Binding IsEditTimetablesEnabled}"/>
<MenuItem x:Name="ViewTimetable" Header="_View timetable" IsEnabled="{Binding IsEditTimetablesEnabled}"/>
<MenuItem x:Name="ViewGraph" Header="View _graph" IsEnabled="{Binding IsEditTimetablesEnabled}"/>
<MenuItem x:Name="ExportTimetable" Header="E_xport ..." IsEnabled="{Binding IsTimetableSelected}"/>
<MenuItem x:Name="ViewTimetable" Header="_View timetable" IsEnabled="{Binding IsTimetableSelected}"/>
<MenuItem x:Name="ViewGraph" Header="View _graph" IsEnabled="{Binding IsTimetableSelectedMultiDirection}"/>
<MenuItem x:Name="Print" Header="_Print"/>
<MenuItem x:Name="ExitApplication" Header="E_xit"/>
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using System.Text;

namespace TimetableTool.Desktop.Models
{
public class TimetableMatrixModel
{

}
}
{
public class DataPoint
{
public double X { get; set; }
public double Y { get; set; }
}
}
7 changes: 4 additions & 3 deletions TimetableTool.Desktop/Models/LoggingModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Logging.Library;
using Caliburn.Micro;
using Logging.Library;
using System;
using System.Collections.Generic;
using System.Text;
Expand All @@ -8,7 +9,7 @@ namespace TimetableTool.Desktop.Models
public class LoggingModel
{
public ILogCollectionManager Logging { get; set; }
public ILogCollectionManager FilteredLogging { get; set; }
public LogFilter Filter { get; set; } = new LogFilter(false,true,true,false);
public BindableCollection<LogEntryClass> FilteredLogging { get; set; }
public LogFilter Filter { get; set; } = new LogFilter(true,true,true,true);
}
}
18 changes: 18 additions & 0 deletions TimetableTool.Desktop/Models/TimeGraphUIModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Caliburn.Micro;
using DataAccess.Library.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media;
using System.Windows.Shapes;

namespace TimetableTool.Desktop.Models
{
public class TimeGraphUIModel
{
public BindableCollection<FullTimeEventModel> TimeEventList { get; set; }= new BindableCollection<FullTimeEventModel>();
public string ServiceInstanceAbbreviation { get; set; } = "";
public string ServiceInstanceName { get; set; } = "";
public BindableCollection<DataPoint> DataLine { get; set; } = new BindableCollection<DataPoint>();
}
}
147 changes: 145 additions & 2 deletions TimetableTool.Desktop/ViewModels/DisplayTimeTableGraphViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,155 @@
using Caliburn.Micro;
using DataAccess.Library.Logic;
using DataAccess.Library.Models;
using System.Collections.Specialized;
using System.Linq;
using TimetableTool.Desktop.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
using TimetableTool.Desktop.Views;

namespace TimetableTool.Desktop.ViewModels
{
public class DisplayTimeTableGraphViewModel: Screen
public class DisplayTimetableGraphViewModel : Screen
{
public int TimetableId { get; set; }

private TimetableModel _timetable;
public TimetableModel Timetable
{
get { return _timetable; }
set { _timetable = value; }
}

private BindableCollection<LocationModel> _locationList = new BindableCollection<LocationModel>();
public BindableCollection<LocationModel> LocationList
{
get { return _locationList; }
set
{
_locationList = value;
NotifyOfPropertyChange(()=>LocationList);
}
}

// This is a trick to tell the code behind that the collection has changed
private int _Dummy=1;

public int Dummy
{
get { return _Dummy; }
set
{
_Dummy = value;
NotifyOfPropertyChange(()=>Dummy);
}
}

private int _timeGraphUIChanged = 1;

public int TimeGraphUIChanged
{
get { return _timeGraphUIChanged; }
set
{
_timeGraphUIChanged = value;
NotifyOfPropertyChange(()=>TimeGraphUIChanged);
}
}


private BindableCollection<TimeGraphUIModel> _timeGraphUI = new BindableCollection<TimeGraphUIModel>();
public BindableCollection<TimeGraphUIModel> TimeGraphUI
{
get { return _timeGraphUI; }
set
{
_timeGraphUI = value;

NotifyOfPropertyChange(()=> TimeGraphUI);
}
}

protected override void OnViewLoaded(object view)
{
base.OnViewLoaded(view);
Timetable = TimetableDataAccess.GetTimetableById(TimetableId);
LocationList =
new BindableCollection<LocationModel>(
LocationDataAccess.GetAllLocationsPerRoute(Timetable.RouteId)
.OrderBy(x => x.Order)
.ToList());
int i = 0;
foreach (var item in LocationList)
{
item.Order = i++;
}


SetPeriod(); // sets start and end time at the graph
Dummy += 1;
LocationList.Refresh();
PrepareDataSet();
TimeGraphUIChanged++;
TimeGraphUI.Refresh();
// NotifyOfPropertyChange(()=>LocationList);
}

private void SetPeriod()
{
var ServiceInstances = new BindableCollection<ServiceInstanceModel>(ServiceInstanceDataAccess.GetServiceInstancesPerTimetable(TimetableId));
GraphCanvasSettings.StartTime = (ServiceInstances.Min(x => x.StartTime)/60)*60;
GraphCanvasSettings.EndTime=(ServiceInstances.Max(x => x.EndTime)/60+1)*60;
}


private void PrepareDataSet()
{
TimeGraphUI= new BindableCollection<TimeGraphUIModel>();
var serviceInstances = new BindableCollection<ServiceInstanceModel>(ServiceInstanceDataAccess.GetServiceInstancesPerTimetable(TimetableId));
foreach (var instance in serviceInstances)
{
var item= new TimeGraphUIModel();
var serviceId = instance.ServiceId;
item.TimeEventList= new BindableCollection<FullTimeEventModel>(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(serviceId));
item.ServiceInstanceName = instance.ServiceInstanceName;
item.ServiceInstanceAbbreviation = instance.ServiceInstanceAbbreviation;
int actualTime = instance.StartTime;
foreach (var fullTimeEvent in item.TimeEventList)
{
actualTime += fullTimeEvent.ArrivalTime;
DataPoint point = GetFirstDataPoint(fullTimeEvent, actualTime);
item.DataLine.Add(point);
if (fullTimeEvent.WaitTime > 0)
{
actualTime += fullTimeEvent.WaitTime;
DataPoint point2 = GetSecondDataPoint(actualTime, point.X);
item.DataLine.Add(point2);
}
}
TimeGraphUI.Add(item);
}
}

private DataPoint GetFirstDataPoint(FullTimeEventModel fullTimeEvent, int actualTime)
{
DataPoint output= new DataPoint();
output.Y = actualTime;
output.X = LocationList.Where(x=>x.Id== fullTimeEvent.LocationId)
.Select(x => x.Order).First();

return output;
}

private DataPoint GetSecondDataPoint(int actualTime, double xValue)
{
DataPoint output= new DataPoint();
output.Y = actualTime;
output.X = xValue;
return output;
}
}
}

Loading

0 comments on commit 7a189b5

Please sign in to comment.