-
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.
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
KitopiaAvalonia/Converter/OnnxModelManagerPage/DataGridModelSizeComparer.cs
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,33 @@ | ||
using System.Collections; | ||
using System.IO; | ||
using Core.SDKs.Services.Plugin; | ||
using PluginCore.Onnx; | ||
|
||
namespace KitopiaAvalonia.Converter.OnnxModelManagerPage; | ||
|
||
public class DataGridModelSizeComparer : IComparer | ||
{ | ||
public static readonly DataGridModelSizeComparer Default = new DataGridModelSizeComparer(); | ||
|
||
public int Compare(object? x, object? y) | ||
{ | ||
if (x is OnnxModelInfoWrapper onnxModelInfoWrapper &&y is OnnxModelInfoWrapper onnxModelInfoWrapper2) | ||
{ | ||
var path = PluginManager.GetPluginByPlgStr(onnxModelInfoWrapper.PluginStr).Path; | ||
var fileInfo = new FileInfo($"{path}{onnxModelInfoWrapper.Model.ModelPath}"); | ||
var path2 = PluginManager.GetPluginByPlgStr(onnxModelInfoWrapper2.PluginStr).Path; | ||
var fileInfo2 = new FileInfo($"{path2}{onnxModelInfoWrapper2.Model.ModelPath}"); | ||
if (fileInfo.Length> fileInfo2.Length) | ||
{ | ||
return 1; | ||
} | ||
|
||
if (fileInfo.Length < fileInfo2.Length) | ||
{ | ||
return -1; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
KitopiaAvalonia/Converter/OnnxModelManagerPage/OnnxModelInfoWrapperToModelSizeCtr.cs
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,42 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using Avalonia.Data.Converters; | ||
using Core.SDKs.Services.Plugin; | ||
using PluginCore.Onnx; | ||
|
||
namespace KitopiaAvalonia.Converter.OnnxModelManagerPage; | ||
|
||
public class OnnxModelInfoWrapperToModelSizeCtr : IValueConverter | ||
{ | ||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
if (value is OnnxModelInfoWrapper onnxModelInfoWrapper) | ||
{ | ||
var path = PluginManager.GetPluginByPlgStr(onnxModelInfoWrapper.PluginStr).Path; | ||
var fileInfo = new FileInfo($"{path}{onnxModelInfoWrapper.Model.ModelPath}"); | ||
if (fileInfo.Exists) | ||
{ | ||
if (fileInfo.Length>1024*1024 * 1024) | ||
{ | ||
return $"{Math.Round((double)fileInfo.Length / (1024 * 1024 * 1024), 2)}GB"; | ||
}else if (fileInfo.Length > 1024 * 1024) | ||
{ | ||
return $"{Math.Round((double)fileInfo.Length / (1024 * 1024), 2)}MB"; | ||
} | ||
else | ||
{ | ||
return $"{Math.Round((double)fileInfo.Length / 1024, 2)}KB"; | ||
} | ||
|
||
} | ||
} | ||
|
||
return "0B"; | ||
} | ||
|
||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
return null; | ||
} | ||
} |
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