Skip to content

Commit

Permalink
first version using SkiaSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmaster187 committed Oct 14, 2024
1 parent 0f6935b commit e152852
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 100 deletions.
281 changes: 193 additions & 88 deletions OSMMapGenerator/OSMMapGenerator.cs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion OSMMapGenerator/OSMMapGeneratorNET8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<AssemblyTitle>OSMMapGenerator</AssemblyTitle>
<Copyright>%24{AuthorCopyright}</Copyright>
<AssemblyVersion>1.1.0</AssemblyVersion>
<StartupObject>TeslaLogger.OSMMapGenerator</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug</OutputPath>
Expand All @@ -19,6 +20,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Drawing.Common" Version="8.0.2" />
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
</ItemGroup>
</Project>
12 changes: 9 additions & 3 deletions TeslaLogger/OSMMapProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public override void CreateTripMap(DataTable coords, int width, int height, MapM
File.WriteAllText(tempfile, JsonConvert.SerializeObject(job), Encoding.UTF8);

GetOSMMapGeneratorFilename(out string fileName, out string arguments);
arguments += "-jobfile " + tempfile + (Program.VERBOSE ? " - debug" : "");
arguments += "-jobfile " + tempfile + (Program.VERBOSE ? " -debug" : "");

Logfile.Log("cmd: " + fileName + " " + arguments);

using (Process process = new Process
{
Expand Down Expand Up @@ -254,14 +256,18 @@ private static void GetOSMMapGeneratorFilename(out string fileName, out string a
else
{
fileName = "/home/cli/dotnet";
arguments = "/etc/teslalogger/OSMMapGenerator.exe ";
if (!File.Exists(fileName))
fileName = "dotnet";

arguments = "OSMMapGeneratorNET8.dll ";

/*
if (!Tools.IsMono())
{
var f = new FileInfo("OSMMapGeneratorNET8.dll");
fileName = f.FullName;
arguments = "";
}
}*/
}
}

Expand Down
2 changes: 1 addition & 1 deletion TeslaLogger/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private static void InitStage2()

try
{
if (Environment.Version?.ToString()?.StartsWith("8.0") == true)
if (Tools.IsDotnet8())
{
ExceptionlessClient.Default.Configuration.DefaultData.Add("dotnet", Environment.Version?.ToString());
ExceptionlessClient.Default.CreateFeatureUsage("USE_DOTNET8").FirstCarUserID().AddObject(Environment.Version.ToString(), "DOTNET8").Submit();
Expand Down
5 changes: 3 additions & 2 deletions TeslaLogger/StaticMapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ private void Work()
int queueLength = queue.Count;
if (queue.TryDequeue(out Request request))
{
//Tools.DebugLog("StaticMapService:Work() queue:" + queue.Count + " MapProvider:" + _StaticMapProvider);
Tools.DebugLog("StaticMapService:Work() queue:" + queue.Count + " MapProvider:" + _StaticMapProvider);
int width = request.Width > 0 ? request.Width : 200;
int height = request.Height > 0 ? request.Height : 150;
if (request is TripRequest)
{
//Tools.DebugLog($"StaticMapService:Work() request:{request.Type} {((TripRequest)request).StartPosID}->{((TripRequest)request).EndPosID}");
string filename = System.IO.Path.Combine(GetMapDir(), GetMapFileName(((TripRequest)request).CarID, ((TripRequest)request).StartPosID, ((TripRequest)request).EndPosID));
Tools.DebugLog("StaticMapService:filename = " + filename);
if (MapFileExistsOrIsTooOld(filename))
{
using (DataTable dt = TripToCoords((TripRequest)request))
Expand Down Expand Up @@ -384,7 +385,7 @@ public static string GetMapDir()
{
string mapdir = "/var/lib/grafana/plugins/teslalogger-timeline-panel/dist/maps";

if (!Tools.IsMono())
if (!Tools.IsMono() && !Tools.IsDotnet8())
mapdir = new DirectoryInfo("maps").FullName;

try
Expand Down
6 changes: 6 additions & 0 deletions TeslaLogger/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal static bool UseNearbySuCService()
public enum UpdateType { all, stable, none };

internal static ConcurrentQueue<Tuple<DateTime, string>> debugBuffer = new ConcurrentQueue<Tuple<DateTime, string>>();
internal static bool dotnet8;

public static void SetThreadEnUS()
{
Expand Down Expand Up @@ -1234,6 +1235,11 @@ public static bool IsUnitTest()
return false;
}

public static bool IsDotnet8()
{
return Environment.Version?.ToString()?.StartsWith("8.0") == true;
}

public static bool IsDockerNET8()
{
try
Expand Down
23 changes: 18 additions & 5 deletions UnitTestsTeslalogger/UnitTestOSMMapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ namespace UnitTestsTeslalogger
[TestClass]
public class UnitTestOSMMapGenerator
{
[TestInitialize]
public void InitializeTests()
{
if (!Directory.Exists("maps"))
Directory.CreateDirectory("maps");
else
{
var files = Directory.GetFiles("maps");
foreach (var file in files)
File.Delete(file);
}
}

[TestMethod]
public void ParkingP1()
{
var f = new FileInfo("../../Testfile-P1.txt");
var f = new FileInfo("../../../Testfile-P1.txt");
string tempfile = GetTempFileName();
f.CopyTo(tempfile,true);

Expand All @@ -35,7 +48,7 @@ public void ParkingP1()
[TestMethod]
public void ParkingP2()
{
var f = new FileInfo("../../Testfile-P2.txt");
var f = new FileInfo("../../../Testfile-P2.txt");
string tempfile = GetTempFileName();
f.CopyTo(tempfile, true);

Expand All @@ -52,7 +65,7 @@ public void ParkingP2()
[TestMethod]
public void ParkingP3()
{
var f = new FileInfo("../../Testfile-P3.txt");
var f = new FileInfo("../../../Testfile-P3.txt");
string tempfile = GetTempFileName();
f.CopyTo(tempfile, true);

Expand All @@ -69,7 +82,7 @@ public void ParkingP3()
[TestMethod]
public void ParkingP4()
{
var f = new FileInfo("../../Testfile-P4.txt");
var f = new FileInfo("../../../Testfile-P4.txt");
string tempfile = GetTempFileName();
f.CopyTo(tempfile, true);

Expand All @@ -86,7 +99,7 @@ public void ParkingP4()
[TestMethod]
public void TripT1()
{
var f = new FileInfo("../../Testfile-T1.txt");
var f = new FileInfo("../../../Testfile-T1.txt");
string tempfile = GetTempFileName();
f.CopyTo(tempfile, true);

Expand Down

0 comments on commit e152852

Please sign in to comment.