<commit_before>﻿using AugmentedSzczecin.Interfaces;
using AugmentedSzczecin.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace AugmentedSzczecin.Services
{
    public class HttpService : IHttpService
    {
        private HttpClient _client = new HttpClient() { BaseAddress = new Uri("http://192.168.3.11:1080/") };

        public async Task<ObservableCollection<PointOfInterest>> GetPointOfInterestList()
        {
            HttpResponseMessage response = await _client.GetAsync("places");
            response.EnsureSuccessStatusCode();
            string json = await response.Content.ReadAsStringAsync();
            if (json == "{}")
            {
                return new ObservableCollection<PointOfInterest>();
        }
            return JsonConvert.DeserializeObject<ObservableCollection<PointOfInterest>>(json);
        }

        public async Task<ObservableCollection<PointOfInterest>> GetPointOfInterestList(double latitude, double longitude, int radius, CategoryType category)
        {
            HttpResponseMessage response = null;
            if (category == CategoryType.ALL)
            {
                response = await _client.GetAsync(string.Format("q?lt={0}&lg={1}&radius={2}", latitude, longitude, radius));
            }
            else
            {
                response = await _client.GetAsync(string.Format("q?lt={0}&lg={1}&radius={2}&cat={3}", latitude, longitude, radius, category));
            }
            response.EnsureSuccessStatusCode();
            string json = await response.Content.ReadAsStringAsync();
            json = "{\"places\":[{\"name\":\"<NAME>go na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5580,\"latitude\":53.4299},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"PLACE\"}, {\"name\":\"<NAME>go na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5590,\"latitude\":53.4390},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"PLACE\"}], \"events\":[{\"name\":\"<NAME>wszego na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5588,\"latitude\":53.4299},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"EVENT\"}, {\"name\":\"<NAME> na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5590,\"latitude\":53.4390},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"EVENT\"}], \"commercial\":[{\"name\":\"<NAME> na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5570,\"latitude\":53.4300},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"COMMERCIAL\"}, {\"name\":\"<NAME>go na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5510,\"latitude\":53.4400},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"COMMERCIAL\"}]}";

            if (json == "{}")
            {
                return new ObservableCollection<PointOfInterest>();
            }

            IList<JToken> results = null;
            switch(category)
            {
                case CategoryType.PLACE:
                    results = PoiQueryResponse.ParsePoiPlacesQuery(json);
                    break;
                case CategoryType.EVENT:
                    results = PoiQueryResponse.ParsePoiEventsQuery(json);
                    break;
                case CategoryType.PERSON:
                    results = PoiQueryResponse.ParsePoiPeopleQuery(json);
                    break;
                case CategoryType.COMMERCIAL:
                    results = PoiQueryResponse.ParsePoiCommercialQuery(json);
                    break;
                case CategoryType.ALL:
                    results = PoiQueryResponse.ParsePoiAllQuery(json);
                    break;
            }

            ObservableCollection<PointOfInterest> pois = new ObservableCollection<PointOfInterest>();<commit_msg>Added temporary json string to test filtering<commit_after>﻿using AugmentedSzczecin.Interfaces;
using AugmentedSzczecin.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace AugmentedSzczecin.Services
{
    public class HttpService : IHttpService
    {
        private HttpClient _client = new HttpClient() { BaseAddress = new Uri("http://192.168.3.11:1080/") };

        public async Task<ObservableCollection<PointOfInterest>> GetPointOfInterestList()
        {
            HttpResponseMessage response = await _client.GetAsync("places");
            response.EnsureSuccessStatusCode();
            string json = await response.Content.ReadAsStringAsync();
            if (json == "{}")
            {
                return new ObservableCollection<PointOfInterest>();
        }
            return JsonConvert.DeserializeObject<ObservableCollection<PointOfInterest>>(json);
        }

        public async Task<ObservableCollection<PointOfInterest>> GetPointOfInterestList(double latitude, double longitude, int radius, CategoryType category)
        {
            HttpResponseMessage response = null;
            if (category == CategoryType.ALL)
            {
                response = await _client.GetAsync(string.Format("q?lt={0}&lg={1}&radius={2}", latitude, longitude, radius));
            }
            else
            {
                response = await _client.GetAsync(string.Format("q?lt={0}&lg={1}&radius={2}&cat={3}", latitude, longitude, radius, category));
            }
            response.EnsureSuccessStatusCode();
            string json = await response.Content.ReadAsStringAsync();

            /****** DO TESTÓW ******/
            json = "{\"places\":[{\"name\":\"<NAME> na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5580,\"latitude\":53.4299},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"PLACE\"}, {\"name\":\"<NAME> na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5590,\"latitude\":53.4390},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"PLACE\"}], \"events\":[{\"name\":\"<NAME>go na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5588,\"latitude\":53.4299},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"EVENT\"}, {\"name\":\"<NAME>go na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5590,\"latitude\":53.4390},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"EVENT\"}], \"commercial\":[{\"name\":\"<NAME>zego na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5570,\"latitude\":53.4300},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"COMMERCIAL\"}, {\"name\":\"<NAME>go na ziemiach polskich kolegium salwatoriaĹskiego oraz grota Matki BoĹźej z Lourdes\",\"location\":{\"longitude\":14.5510,\"latitude\":53.4400},\"address\":{\"street\":\"GĹowackiego 3 w dzielnicy Salwator\"},\"subcategory\":\"MONUMENT\",\"category\":\"COMMERCIAL\"}]}";
            /***********************/

            if (json == "{}")
            {
                return new ObservableCollection<PointOfInterest>();
            }

            IList<JToken> results = null;
            switch(category)
            {
                case CategoryType.PLACE:
                    results = PoiQueryResponse.ParsePoiPlacesQuery(json);
                    break;
                case CategoryType.EVENT:
                    results = PoiQueryResponse.ParsePoiEventsQuery(json);
                    break;
                case CategoryType.PERSON:
                    results = PoiQueryResponse.ParsePoiPeopleQuery(json);
                    break;
                case CategoryType.COMMERCIAL:
                    results = PoiQueryResponse.ParsePoiCommercialQuery(json);
                    break;
                case CategoryType.ALL:
                    results = PoiQueryResponse.ParsePoiAllQuery(json);
                    break;
            }

            ObservableCollection<PointOfInterest> pois = new ObservableCollection<PointOfInterest>();
{'fraction_non_alphanumeric': 0.16064385459972286, 'fraction_numerical': 0.020893294957893615, 'mean_word_length': 2.901039501039501, 'pattern_counts': {'":': 102, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4737973', 'n_tokens_mistral': 2902, 'n_tokens_neox': 2785, 'n_words': 469}