-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
16 changed files
with
702 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
147
TimetableTool.Desktop/ViewModels/DisplayTimeTableGraphViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.