Browse Source

Merge pull request #4 from NuarkNoir/enhancement-model-size-preview

pull/39/head
Ionite 1 year ago committed by GitHub
parent
commit
7cc5ab9fc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      StabilityMatrix/App.xaml.cs
  2. 10
      StabilityMatrix/CheckpointBrowserPage.xaml
  3. 2
      StabilityMatrix/Models/Api/CivitFile.cs
  4. 23
      StabilityMatrix/Models/Api/CivitModel.cs
  5. 36
      StabilityMatrix/Models/FileSizeType.cs

2
StabilityMatrix/App.xaml.cs

@ -243,7 +243,7 @@ namespace StabilityMatrix
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
})
};
// HTTP Policies
var retryStatusCodes = new[] {
HttpStatusCode.RequestTimeout, // 408

10
StabilityMatrix/CheckpointBrowserPage.xaml

@ -113,9 +113,15 @@
Appearance="Primary"
Command="{Binding ImportCommand}"
CommandParameter="{Binding CivitModel}"
Content="Import"
HorizontalAlignment="Stretch"
Margin="0,8,0,0" />
Margin="0,8,0,0">
<ui:Button.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Import - "/>
<TextBlock Text="{Binding CivitModel.FullFilesSize}"/>
</StackPanel>
</ui:Button.Content>
</ui:Button>
</Grid>
</StackPanel>
</ui:Card>

2
StabilityMatrix/Models/Api/CivitFile.cs

@ -5,7 +5,7 @@ namespace StabilityMatrix.Models.Api;
public class CivitFile
{
[JsonPropertyName("sizeKb")]
[JsonPropertyName("sizeKB")]
public double SizeKb { get; set; }
[JsonPropertyName("pickleScanResult")]

23
StabilityMatrix/Models/Api/CivitModel.cs

@ -36,4 +36,27 @@ public class CivitModel
[BsonRef("ModelVersions")]
[JsonPropertyName("modelVersions")]
public List<CivitModelVersion>? ModelVersions { get; set; }
private FileSizeType? _fullFilesSize;
public FileSizeType FullFilesSize
{
get
{
if (_fullFilesSize == null)
{
var kbs = 0.0;
if (ModelVersions is not null)
{
var latestVersion = ModelVersions[0];
if (latestVersion.Files is not null)
{
var latestModelFile = latestVersion.Files[0];
kbs = latestModelFile.SizeKb;
}
}
_fullFilesSize = new FileSizeType(kbs);
}
return _fullFilesSize;
}
}
}

36
StabilityMatrix/Models/FileSizeType.cs

@ -0,0 +1,36 @@
using System.Globalization;
namespace StabilityMatrix.Models;
public class FileSizeType
{
public double SizeInKB { get; private set; }
public string HumanReadableRepresentation { get; private set; }
public FileSizeType(double sizeInKB)
{
SizeInKB = sizeInKB;
HumanReadableRepresentation = ConvertToHumanReadable();
}
private string ConvertToHumanReadable()
{
var sizeUnits = new string[] { "KB", "MB", "GB", "TB" };
var size = SizeInKB;
var unitIndex = 0;
while (size >= 1024 && unitIndex < sizeUnits.Length - 1)
{
size /= 1024;
unitIndex++;
}
return string.Format("{0} {1}", size.ToString("0.##", CultureInfo.InvariantCulture), sizeUnits[unitIndex]);
}
public override string ToString()
{
return HumanReadableRepresentation;
}
}
Loading…
Cancel
Save