Esempio n. 1
0
        // declaring another method to handle a single string array – put each task in a separate method and group similar methods into classes
        public Event BuildEvent(FeedFixture fixture)
        {
            // in the array, each position will be one bit of data
            // i.e. originalJson[0] might be the home team
            // originalJson[1] might be the away team etc.
            // you’ll have to work all this out and populate the event, then return that event
            Event newEvent = new Event();

            newEvent.date = convertdate(fixture.date);
            newEvent.hometeam = fixture.homeTeamName;
            newEvent.href = fixture._links.self["href"];
            newEvent.awayteam = fixture.awayTeamName;

            // etc. etc.
            return newEvent;
        }
Esempio n. 2
0
        public Event findClosestEvent(List<Event> originalEvents)
        {
            Event shortDistanceEvent = new Event();
            int numberOfEventsInList = originalEvents.Count();
            int distance = FixtureRetriever.REALLY_REALLY_BIG_NUMBER;

            foreach (Event e in originalEvents)
            {
                if (distance > e.duration)
                {
                    distance = e.duration;
                    shortDistanceEvent = e;
                }
            }

            return shortDistanceEvent;
        }
        public Event PopulateEventWithDistances(Event currentEvent, String locationA, string travelmode)
        {
            // setting up the variables
            ApiCaller api = new ApiCaller();
            JSONparserdistances jsonParser = new JSONparserdistances(); // Changed this too the new JSON parser
            String apiAddress = "https://maps.googleapis.com/maps/api/distancematrix/json";

            String addressToCall = apiAddress + "?" + origin(locationA) + "&" + destination(currentEvent.locationLatitude, currentEvent.locationLongitude) + "&" + mode(travelmode) + "&" + apiKey();

            // calling the api
            String jsonString = api.GET(addressToCall);

            currentEvent.distance = jsonParser.extractDistanceFromGoogleMapsJsonString(jsonString);
            currentEvent.duration = jsonParser.extractTimeTakenFromGoogleMapsJsonString(jsonString);
            currentEvent.durationFriendly = jsonParser.extractFriendlyTimeTakenFromGoogleMapsJsonString(jsonString);
            currentEvent.distanceFriendly = convertFromMetersToMiles(currentEvent.distance);

            return currentEvent;
        }