fix: Optimize configuration items

master
Tongg 8 months ago
parent 667892e353
commit 5cd01f2caf
  1. 149
      Model/Entity/AgileJsonConfigEntity.cs
  2. 21
      Model/Services/SOCClientService.cs
  3. 116
      ViewModel/Configuration/AlgorithmConfigVM.cs
  4. 24
      Views/Configuration/AlgorithmConfigPage.xaml

@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using HandyControl.Collections;
using SparkClient.ViewModel.Configuration;
namespace SparkClient.Model.Entity;
@ -8,29 +9,46 @@ public class AgileJsonConfigEntity
{
public readonly List<string> Keys;
private ManualObservableCollection<string> _runKey;
public ManualObservableCollection<string> RunKey {
get => _runKey;
set
{
_runKey = value;
OnPropertyChanged(nameof(RunKey));
}
}
public AgileJsonConfigEntity( List<string> keys)
{
Shape = "圆形";
ModeValue = "999";
SpecValue = "999";
Keys = keys;
JsonKeys = keys;
ModeList = GetRunModelList();
SpceList = GetRunSpecList();
_mode = ModeList.FirstOrDefault();
_spec = SpceList.FirstOrDefault();
RunKey = new ManualObservableCollection<string>(keys);
}
private Param _mode;
public Param Mode
private string _modeValue;
public string ModeValue
{
get => _modeValue;
set
{
get => _mode;
set => SetField(ref _mode, value);
SetField(ref _modeValue, value);
OnPropertyChanged(nameof(ModeValue));
}
private Param _spec;
public Param Spec
}
private string _specValue;
public string SpecValue
{
get => _spec;
set => SetField(ref _spec, value);
get => _specValue;
set
{
SetField(ref _specValue, value);
OnPropertyChanged(nameof(SpecValue));
}
}
private string _shape;
@ -48,6 +66,8 @@ public class AgileJsonConfigEntity
set
{
SetField(ref _jsonKey, value);
OnPropertyChanged(nameof(JsonKey));
FilterItems(value);
}
}
@ -57,28 +77,21 @@ public class AgileJsonConfigEntity
get => _value;
set => SetField(ref _value, value);
}
private List<string> _jsonKeys;
public List<string> JsonKeys
private void FilterItems(string key)
{
get => _jsonKeys;
set => SetField(ref _jsonKeys, value);
}
private List<Param> _modeList;
public List<Param> ModeList
RunKey.CanNotify = false;
RunKey.Clear();
foreach (var data in Keys)
{
if (data.ToLower().Contains(key.ToLower()))
{
get => _modeList;
set => SetField(ref _modeList, value);
RunKey.Add(data);
}
private List<Param> _specList;
}
if(RunKey.Count <= 0)
RunKey.Add(key);
RunKey.CanNotify = true;
public List<Param> SpceList
{
get => _specList;
set => SetField(ref _specList, value);
}
@ -95,77 +108,5 @@ public class AgileJsonConfigEntity
OnPropertyChanged(name);
return true;
}
public List<Param> GetRunModelList()
{
return new List<Param>
{
new Param()
{
Value = "0",
Name = "实验室模式"
},
new Param()
{
Value = "1",
Name = "工厂模式"
}
};
}
public List<Param> GetRunSpecList()
{
return new List<Param>
{
new Param()
{
Value = "P8-P8",
Name = "P8-P8"
},
new Param()
{
Value = "P8-P8-S1",
Name = "P8-P8-S1"
},
new Param()
{
Value = "P8-P8-S2",
Name = "P8-P8-S2"
},
new Param()
{
Value = "P8-P8-S3",
Name = "P8-P8-S3"
},
new Param()
{
Value = "P8-P8-S4",
Name = "P8-P8-S4"
},
new Param()
{
Value = "P8-P8-S5",
Name = "P8-P8-S5"
},
new Param()
{
Value = "P8-P8-S6",
Name = "P8-P8-S6"
},
new Param()
{
Value = "P8-P8-S7",
Name = "P8-P8-S7"
},
new Param()
{
Value = "P8-P8-S8",
Name = "P8-P8-S8"
}
};
}
}
public class Param
{
public string Value { get; set; }
public string Name { get; set; }
}

@ -204,22 +204,25 @@ namespace SparkClient.Model.Services
throw new Exception("No data found for the specified keys.");
}
StringBuilder sbParams = new StringBuilder();
foreach (DataRow row in table.Rows)
{
string key = row["Key"].ToString() ?? string.Empty;
string value = row["Value"].ToString() ?? string.Empty;
if (key == "light_level" && int.TryParse(value, out int parsedLightLevel))
{
lightLevel = parsedLightLevel; // 光照度
}
else if (key == "half_circle")
{
halfCircle = value; // 半圆
}
// if (key == "light_level" && int.TryParse(value, out int parsedLightLevel))
// {
// lightLevel = parsedLightLevel; // 光照度
// }
// else if (key == "half_circle")
// {
// halfCircle = value; // 半圆
// }
sbParams.Append($"{key}={value}&");
}
string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}";
// string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}";
string url = $"{_baseUrl}/collect_images?{sbParams.ToString().Substring(0, sbParams.ToString().Length - 1)}";
var result = SendGetRequestAsync<ResponseStatus>(url);

@ -35,9 +35,32 @@ public class AlgorithmConfigVM : BaseViewModel
}
}
private ObservableCollection<Param> _modeList;
public ObservableCollection<Param> ModeList
{
get => _modeList;
set
{
_modeList = value;
OnPropertyChanged(nameof(ModeList));
}
}
public List<string> _jsonKeysBak;
private ObservableCollection<Param> _specList;
public ObservableCollection<Param> SpecList
{
get => _specList;
set {
_specList = value;
OnPropertyChanged(nameof(ModeList));
}
}
public List<string> _jsonKeysBak;
public List<string> JsonKeysBak
{
get => _jsonKeysBak;
}
private bool _isEnabled;
public bool IsEnabled { get { return _isEnabled; } set { _isEnabled = value; OnPropertyChanged(nameof(IsEnabled)); } }
@ -48,6 +71,8 @@ public class AlgorithmConfigVM : BaseViewModel
SaveAlgorithmDataCommand = new RelayCommand(SaveAlgorithmData);
BeautifyJsonCommand = new RelayCommand(BeautifyJson);
UglifyJsonCommand = new RelayCommand(UglifyJson);
ModeList = GetRunModelList();
SpecList = GetRunSpecList();
InitAlgorithmData(null);
IsEnabledByRole();
_jsonKeysBak = GetNestedKeys(JObject.Parse(AlgorithmConfigJson));
@ -69,15 +94,20 @@ public class AlgorithmConfigVM : BaseViewModel
{
AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak)
{
Mode = baseData.ModeList.Find(e => e.Value.Equals(row["Mode"].ToSafeString())),
Spec = baseData.SpceList.Find(e => e.Value.Equals(row["Spec"].ToSafeString())),
ModeValue = row["Mode"].ToSafeString(),
SpecValue = row["Spec"].ToSafeString(),
Shape = row["Shape"].ToSafeString(),
JsonKey = row["JsonKey"].ToSafeString(),
Value = row["Value"].ToSafeString()
});
} catch { }
}
catch (Exception ex)
{
Logger.Error(ex.Message);
}
}
}
}
[Log]
private bool CheckAndSaveAgileJson()
@ -89,10 +119,10 @@ public class AlgorithmConfigVM : BaseViewModel
if (string.IsNullOrWhiteSpace(row.JsonKey) || string.IsNullOrWhiteSpace(row.Value) ||
string.IsNullOrWhiteSpace(row.Shape))
continue;
if (row.Mode == null || row.Spec == null)
if (row.ModeValue.IsNullOrEmpty()|| row.SpecValue.IsNullOrEmpty())
continue;
insertSql.Add($"INSERT INTO AGILE_ALGORITHM_CONFIG (GUID, Mode, Spec, Shape, JsonKey, Value)" +
$@"VALUES ('{row.GenerateSign()}',{row.Mode.Value},'{row.Spec.Value}','{row.Shape}','{row.JsonKey}','{row.Value}');");
$@"VALUES ('{row.GenerateSign()}',{row.ModeValue},'{row.SpecValue}','{row.Shape}','{row.JsonKey}','{row.Value}');");
finalSaveData.Add(row);
}
@ -204,6 +234,7 @@ public class AlgorithmConfigVM : BaseViewModel
// 命令实现
public ICommand AddCommand => new RelayCommand((param) =>
{
string data = GetAlgorithmConfig("P8 P8");
AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak));
});
@ -341,6 +372,77 @@ public class AlgorithmConfigVM : BaseViewModel
return AlgorithmConfigJson;
}
public ObservableCollection<Param> GetRunModelList()
{
return new ObservableCollection<Param>
{
new Param()
{
Value = "0",
Name = "实验室模式"
},
new Param()
{
Value = "1",
Name = "工厂模式"
}
};
}
public ObservableCollection<Param> GetRunSpecList()
{
return new ObservableCollection<Param>
{
new Param()
{
Value = "P8-P8",
Name = "P8-P8"
},
new Param()
{
Value = "P8-P8-S1",
Name = "P8-P8-S1"
},
new Param()
{
Value = "P8-P8-S2",
Name = "P8-P8-S2"
},
new Param()
{
Value = "P8-P8-S3",
Name = "P8-P8-S3"
},
new Param()
{
Value = "P8-P8-S4",
Name = "P8-P8-S4"
},
new Param()
{
Value = "P8-P8-S5",
Name = "P8-P8-S5"
},
new Param()
{
Value = "P8-P8-S6",
Name = "P8-P8-S6"
},
new Param()
{
Value = "P8-P8-S7",
Name = "P8-P8-S7"
},
new Param()
{
Value = "P8-P8-S8",
Name = "P8-P8-S8"
}
};
}
}
public class Param
{
public string Value { get; set; }
public string Name { get; set; }
}

@ -137,11 +137,10 @@
<DataGridTemplateColumn Header="运行模式" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding ModeList}"
SelectedValue="{Binding Mode.Value}"
DisplayMemberPath="Name"
SelectedIndex="1"
SelectedValuePath="Value"/>
<ComboBox ItemsSource="{Binding DataContext.ModeList, RelativeSource={RelativeSource AncestorType=DataGrid}}"
SelectedValue="{Binding ModeValue, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name" SelectedValuePath="Value"
/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
@ -158,12 +157,10 @@
<DataGridTemplateColumn Header="规格" Width="2*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding SpceList}"
SelectedValue="{Binding Spec.Value}"
DisplayMemberPath="Name"
SelectedIndex="1"
SelectedValuePath="Value"/>
<ComboBox ItemsSource="{Binding DataContext.SpecList, RelativeSource={RelativeSource AncestorType=DataGrid}}"
SelectedValue="{Binding SpecValue, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name" SelectedValuePath="Value"
/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@ -172,8 +169,9 @@
<DataGridTemplateColumn Header="JSON Key" Width="3*" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<hc:AutoCompleteTextBox IsTextSearchEnabled="True" Text="{Binding JsonKey, Mode=TwoWay}"
ItemsSource="{Binding JsonKeys}" />
<hc:AutoCompleteTextBox
Text="{Binding JsonKey, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding RunKey}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Loading…
Cancel
Save