-
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.
setup storing metrics in memory and serve by url
- Loading branch information
Showing
4 changed files
with
66 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
using System.Collections.Concurrent; | ||
using System.Text.Json; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Excursion360.Desktop.Services; | ||
|
||
public interface IStateImagesMetricsStore | ||
{ | ||
void IncrementImageHit(string path); | ||
string[] MostPopularUrls(); | ||
} | ||
|
||
public partial class InMemoryIStateImagesMetricsStore : IStateImagesMetricsStore | ||
{ | ||
/// <summary> | ||
/// Количества получений картинок по адресу. ключ = адрес картинки. Значение - количество получений. | ||
/// </summary> | ||
private readonly ConcurrentDictionary<string, int> | ||
hitCounts = new(); | ||
private Regex stateAndImageRegex = GetStateAndImageRegex(); | ||
public void IncrementImageHit(string path) | ||
{ | ||
var match = stateAndImageRegex.Match(path); | ||
if (!match.Success) | ||
{ | ||
return; | ||
} | ||
hitCounts.AddOrUpdate(path, 1, (_, old) => old + 1); | ||
Console.WriteLine(JsonSerializer.Serialize(hitCounts, new JsonSerializerOptions | ||
{ | ||
WriteIndented = true, | ||
})); | ||
} | ||
public string[] MostPopularUrls() | ||
{ | ||
return hitCounts | ||
.OrderByDescending(kvp => kvp.Value) | ||
.ThenBy(kvp => kvp.Key) | ||
.Select(kvp => kvp.Key) | ||
.Take(10) | ||
.ToArray(); | ||
} | ||
|
||
[GeneratedRegex(@"state_.+[/\\].+\.jpg$")] | ||
private static partial Regex GetStateAndImageRegex(); | ||
|
||
} |
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 +1,6 @@ | ||
# Возможность выбирать используемый браузер из установленных на ПК | ||
- `v4.0` | ||
- Обновлен .NET/Nuke до 8, убраны все предупреждения | ||
- Обновлена структура проекта до последней версии ASP.NET Core | ||
- Базовая папка для выбора экскурсий может выбираться через `--excursionsPath путь_к_папке` | ||
- Добавлена обработка `/eapi/preload.json`, по которому будут отдаваться адреса изображений, которые чаще всего просматриваются | ||
- `v3.0` Возможность выбирать используемый браузер из установленных на ПК |