Skip to content

Commit

Permalink
chore: Update namespaces to use CentralPennIncidentsFunc instead of L…
Browse files Browse the repository at this point in the history
…ancoIncidentsFunc
  • Loading branch information
myty committed Jun 21, 2024
1 parent 94672c6 commit 805f7cc
Show file tree
Hide file tree
Showing 28 changed files with 133 additions and 107 deletions.
4 changes: 2 additions & 2 deletions apps/func/src/CentralPennIncidentsFunc/API/Incidents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System.Text.Json;
using System.Threading.Tasks;
using AutoMapper;
using LancoIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Interfaces;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace LancoIncidentsFunc.API
namespace CentralPennIncidentsFunc.API
{
public class Incidents
{
Expand Down
2 changes: 1 addition & 1 deletion apps/func/src/CentralPennIncidentsFunc/Dtos/Incident.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Text.Json.Serialization;

namespace LancoIncidentsFunc.Dtos
namespace CentralPennIncidentsFunc.Dtos
{
public class Incident
{
Expand Down
2 changes: 1 addition & 1 deletion apps/func/src/CentralPennIncidentsFunc/Dtos/Location.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace LancoIncidentsFunc.Dtos
namespace CentralPennIncidentsFunc.Dtos
{
public class Location
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AutoMapper;

namespace LancoIncidentsFunc.Dtos.Mappings
namespace CentralPennIncidentsFunc.Dtos.Mappings
{
public class IncidentProfile : Profile
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AutoMapper;

namespace LancoIncidentsFunc.Dtos.Mappings
namespace CentralPennIncidentsFunc.Dtos.Mappings
{
public class LocationProfile : Profile
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;

namespace LancoIncidentsFunc.IncidentProviders;
namespace CentralPennIncidentsFunc.IncidentProviders;

public abstract class BaseIncidentProvider : IIncidentProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;

namespace LancoIncidentsFunc.IncidentProviders;
namespace CentralPennIncidentsFunc.IncidentProviders;

public class LancasterIncidentProvider : BaseIncidentProvider
{
Expand Down Expand Up @@ -41,7 +41,8 @@ public override async Task<IEnumerable<Incident>> GetIncidentsAsync()
var cts = new CancellationTokenSource();
var rss = await XDocument.LoadAsync(xmlStream, LoadOptions.None, cts.Token);

var incidents = rss.Root.Descendants("item")
var incidents = rss
.Root.Descendants("item")
.Select(itm =>
{
var descSplit = itm.Element("description").Value.Split(';');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;
using HtmlAgilityPack;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using Microsoft.OData.Edm;

namespace LancoIncidentsFunc.IncidentProviders;
namespace CentralPennIncidentsFunc.IncidentProviders;

public class YorklIncidentProvider : BaseIncidentProvider
{
Expand Down Expand Up @@ -41,49 +41,62 @@ public override async Task<IEnumerable<Incident>> GetIncidentsAsync()
var doc = new HtmlDocument();
doc.LoadHtml(htmlSource);

var incidents = doc.DocumentNode.Descendants("table")
var incidents = doc
.DocumentNode.Descendants("table")
.Where(x => x.Attributes["class"]?.Value == "incidentList")
.SelectMany(
y =>
y.ChildNodes.Skip(3)
.Select(
tr =>
tr.ChildNodes.Where(node => node.NodeType == HtmlNodeType.Element)
.ToList()
)
.Where(cells => cells.Count > 0)
.Select(cells =>
{
var type = cells.FirstOrDefault()?.InnerText;
var subType = cells.Skip(3).FirstOrDefault()?.InnerText;
var location = cells.Skip(6).FirstOrDefault()?.InnerText;
var area = cells.Skip(7).FirstOrDefault()?.InnerText;
var date = cells.Skip(1)?.FirstOrDefault()?.InnerText;
var id =
cells
.Skip(8)
?.FirstOrDefault()
?.InnerHtml
.Split('?')
.Skip(1)
.FirstOrDefault()
?.Split('"')
.FirstOrDefault() ?? $"{Guid.NewGuid()}";
.SelectMany(y =>
y.ChildNodes.Skip(2)
.Select(tr =>
tr.ChildNodes.Where(node => node.NodeType == HtmlNodeType.Element).ToList()
)
.Where(cells => cells.Count > 0)
.Select(cells =>
{
var type = cells.FirstOrDefault()?.InnerText;
var subType = cells.Skip(3).FirstOrDefault()?.InnerText;
var street = cells.Skip(4).FirstOrDefault()?.InnerText;
var crossStreet = cells.Skip(5).FirstOrDefault()?.InnerText;
var nearestIntersection = cells.Skip(6).FirstOrDefault()?.InnerText;
var area = cells.Skip(7).FirstOrDefault()?.InnerText;
var date = cells.Skip(1)?.FirstOrDefault()?.InnerText;
var id =
cells
.Skip(8)
?.FirstOrDefault()
?.InnerHtml.Split('?')
.Skip(1)
.FirstOrDefault()
?.Split('"')
.FirstOrDefault() ?? $"{Guid.NewGuid()}";

return new Incident(Key, id)
{
Type = type,
SubType = subType,
Area = area,
Location = location,
IncidentDate = Date.Parse(date)
};
})
return new Incident(Key, id)
{
Type = type,
SubType = subType,
Area = area,
Location = FormatLocation(street, crossStreet, nearestIntersection),
IncidentDate = Date.Parse(date)
};
})
)
.ToList();

_feedCache.SaveValue(Source, incidents);

return incidents;
}

private static string FormatLocation(
string street,
string crossStreet,
string nearestIntersection
)
{
if (!string.IsNullOrWhiteSpace(nearestIntersection))
{
return nearestIntersection;
}

return $"{street} / {crossStreet}";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Models;

namespace LancoIncidentsFunc.Interfaces
namespace CentralPennIncidentsFunc.Interfaces
{
public interface IDataCache<TKey, TValue>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace LancoIncidentsFunc.Interfaces
namespace CentralPennIncidentsFunc.Interfaces
{
public interface IEnvironmentProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Models;

namespace LancoIncidentsFunc.Interfaces;
namespace CentralPennIncidentsFunc.Interfaces;

public interface IFeedService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Models;

namespace LancoIncidentsFunc.Interfaces;
namespace CentralPennIncidentsFunc.Interfaces;

public interface IIncidentProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Threading.Tasks;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Models;
using Microsoft.Azure.Cosmos.Table;

namespace LancoIncidentsFunc.Interfaces
namespace CentralPennIncidentsFunc.Interfaces
{
public interface ILocationRepository
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Threading.Tasks;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Models;

namespace LancoIncidentsFunc.Interfaces
namespace CentralPennIncidentsFunc.Interfaces
{
public interface ILocationService
{
Expand Down
2 changes: 1 addition & 1 deletion apps/func/src/CentralPennIncidentsFunc/Models/Incident.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using System.Text;

namespace LancoIncidentsFunc.Models
namespace CentralPennIncidentsFunc.Models
{
public class Incident
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Net;
using Microsoft.Azure.Cosmos.Table;

namespace LancoIncidentsFunc.Models
namespace CentralPennIncidentsFunc.Models
{
public class LocationEntity : TableEntity
{
Expand Down
15 changes: 8 additions & 7 deletions apps/func/src/CentralPennIncidentsFunc/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using LancoIncidentsFunc.IncidentProviders;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using LancoIncidentsFunc.Providers;
using LancoIncidentsFunc.Repositories;
using LancoIncidentsFunc.Services;
using CentralPennIncidentsFunc.IncidentProviders;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;
using CentralPennIncidentsFunc.Providers;
using CentralPennIncidentsFunc.Repositories;
using CentralPennIncidentsFunc.Services;
using CentralPennIncidentsFunc.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace LancoIncidentsFunc
namespace CentralPennIncidentsFunc
{
public class Program
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using LancoIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Interfaces;

namespace LancoIncidentsFunc.Providers
namespace CentralPennIncidentsFunc.Providers
{
public class EnvironmentProvider : IEnvironmentProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;
using Microsoft.Azure.Cosmos.Table;

namespace LancoIncidentsFunc.Repositories
namespace CentralPennIncidentsFunc.Repositories
{
public class LocationRepository : ILocationRepository
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using LancoIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Interfaces;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace LancoIncidentsFunc.Schedules
namespace CentralPennIncidentsFunc.Schedules
{
public class EndPointKeepWarm
{
Expand Down
6 changes: 3 additions & 3 deletions apps/func/src/CentralPennIncidentsFunc/Services/FeedCache.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;
using Microsoft.Extensions.Caching.Memory;

namespace LancoIncidentsFunc.Services
namespace CentralPennIncidentsFunc.Services
{
public class FeedCache : IDataCache<string, IEnumerable<Incident>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;
using Microsoft.Extensions.Logging;

namespace LancoIncidentsFunc.Services;
namespace CentralPennIncidentsFunc.Services;

public class FeedService : IFeedService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using LancoIncidentsFunc.Interfaces;
using LancoIncidentsFunc.Models;
using CentralPennIncidentsFunc.Interfaces;
using CentralPennIncidentsFunc.Models;
using Microsoft.Extensions.Caching.Memory;

namespace LancoIncidentsFunc.Services
namespace CentralPennIncidentsFunc.Services
{
public class LocationCache : IDataCache<(string, string), LocationEntity>
{
Expand Down
Loading

0 comments on commit 805f7cc

Please sign in to comment.