-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTrafficChecks.cs
41 lines (37 loc) · 1.16 KB
/
TrafficChecks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace TwitterTraffic
{
public class TrafficChecks
{
private string ConnectionString;
/// <summary>
/// Gets latest traffic between origin and destination
/// </summary>
/// <param name="origin"></param>
/// <param name="destination"></param>
/// <param name="via"></param>
/// <returns></returns>
public int CheckTrafficDelay(string origin, string destination, string via = "")
{
string jsonTraffic = GetLatestTraffic(String.Format(ConnectionString, origin, destination));
TrafficReport trafficReport = Utils.Deserialise<TrafficReport>(jsonTraffic);
int duration = trafficReport.routes[0].legs[0].duration.value;
int durationInTraffic = trafficReport.routes[0].legs[0].duration_in_traffic.value;
return Math.Abs((durationInTraffic - duration) / 60);
}
private string GetLatestTraffic(string connectionString)
{
WebClient wc = new WebClient();
return wc.DownloadString(connectionString);
}
public TrafficChecks(string connectionString)
{
ConnectionString = connectionString;
}
}
}