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.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using HandyControl.Collections;
using SparkClient.ViewModel.Configuration; using SparkClient.ViewModel.Configuration;
namespace SparkClient.Model.Entity; namespace SparkClient.Model.Entity;
@ -8,29 +9,46 @@ public class AgileJsonConfigEntity
{ {
public readonly List<string> Keys; 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) public AgileJsonConfigEntity( List<string> keys)
{ {
Shape = "圆形"; Shape = "圆形";
ModeValue = "999";
SpecValue = "999";
Keys = keys; Keys = keys;
JsonKeys = keys; RunKey = new ManualObservableCollection<string>(keys);
ModeList = GetRunModelList();
SpceList = GetRunSpecList();
_mode = ModeList.FirstOrDefault();
_spec = SpceList.FirstOrDefault();
} }
private Param _mode;
public Param Mode private string _modeValue;
public string ModeValue
{
get => _modeValue;
set
{ {
get => _mode; SetField(ref _modeValue, value);
set => SetField(ref _mode, value); OnPropertyChanged(nameof(ModeValue));
} }
}
private Param _spec; private string _specValue;
public Param Spec public string SpecValue
{ {
get => _spec; get => _specValue;
set => SetField(ref _spec, value); set
{
SetField(ref _specValue, value);
OnPropertyChanged(nameof(SpecValue));
}
} }
private string _shape; private string _shape;
@ -48,6 +66,8 @@ public class AgileJsonConfigEntity
set set
{ {
SetField(ref _jsonKey, value); SetField(ref _jsonKey, value);
OnPropertyChanged(nameof(JsonKey));
FilterItems(value);
} }
} }
@ -57,28 +77,21 @@ public class AgileJsonConfigEntity
get => _value; get => _value;
set => SetField(ref _value, value); set => SetField(ref _value, value);
} }
private void FilterItems(string key)
private List<string> _jsonKeys;
public List<string> JsonKeys
{ {
get => _jsonKeys; RunKey.CanNotify = false;
set => SetField(ref _jsonKeys, value); RunKey.Clear();
} foreach (var data in Keys)
{
private List<Param> _modeList; if (data.ToLower().Contains(key.ToLower()))
public List<Param> ModeList
{ {
get => _modeList; RunKey.Add(data);
set => SetField(ref _modeList, value);
} }
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); OnPropertyChanged(name);
return true; 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."); throw new Exception("No data found for the specified keys.");
} }
StringBuilder sbParams = new StringBuilder();
foreach (DataRow row in table.Rows) foreach (DataRow row in table.Rows)
{ {
string key = row["Key"].ToString() ?? string.Empty; string key = row["Key"].ToString() ?? string.Empty;
string value = row["Value"].ToString() ?? string.Empty; string value = row["Value"].ToString() ?? string.Empty;
if (key == "light_level" && int.TryParse(value, out int parsedLightLevel)) // if (key == "light_level" && int.TryParse(value, out int parsedLightLevel))
{ // {
lightLevel = parsedLightLevel; // 光照度 // lightLevel = parsedLightLevel; // 光照度
} // }
else if (key == "half_circle") // else if (key == "half_circle")
{ // {
halfCircle = value; // 半圆 // 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); 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; private bool _isEnabled;
public bool IsEnabled { get { return _isEnabled; } set { _isEnabled = value; OnPropertyChanged(nameof(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); SaveAlgorithmDataCommand = new RelayCommand(SaveAlgorithmData);
BeautifyJsonCommand = new RelayCommand(BeautifyJson); BeautifyJsonCommand = new RelayCommand(BeautifyJson);
UglifyJsonCommand = new RelayCommand(UglifyJson); UglifyJsonCommand = new RelayCommand(UglifyJson);
ModeList = GetRunModelList();
SpecList = GetRunSpecList();
InitAlgorithmData(null); InitAlgorithmData(null);
IsEnabledByRole(); IsEnabledByRole();
_jsonKeysBak = GetNestedKeys(JObject.Parse(AlgorithmConfigJson)); _jsonKeysBak = GetNestedKeys(JObject.Parse(AlgorithmConfigJson));
@ -69,15 +94,20 @@ public class AlgorithmConfigVM : BaseViewModel
{ {
AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak) AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak)
{ {
Mode = baseData.ModeList.Find(e => e.Value.Equals(row["Mode"].ToSafeString())), ModeValue = row["Mode"].ToSafeString(),
Spec = baseData.SpceList.Find(e => e.Value.Equals(row["Spec"].ToSafeString())), SpecValue = row["Spec"].ToSafeString(),
Shape = row["Shape"].ToSafeString(), Shape = row["Shape"].ToSafeString(),
JsonKey = row["JsonKey"].ToSafeString(), JsonKey = row["JsonKey"].ToSafeString(),
Value = row["Value"].ToSafeString() Value = row["Value"].ToSafeString()
}); });
} catch { } }
catch (Exception ex)
{
Logger.Error(ex.Message);
}
} }
} }
} }
[Log] [Log]
private bool CheckAndSaveAgileJson() private bool CheckAndSaveAgileJson()
@ -89,10 +119,10 @@ public class AlgorithmConfigVM : BaseViewModel
if (string.IsNullOrWhiteSpace(row.JsonKey) || string.IsNullOrWhiteSpace(row.Value) || if (string.IsNullOrWhiteSpace(row.JsonKey) || string.IsNullOrWhiteSpace(row.Value) ||
string.IsNullOrWhiteSpace(row.Shape)) string.IsNullOrWhiteSpace(row.Shape))
continue; continue;
if (row.Mode == null || row.Spec == null) if (row.ModeValue.IsNullOrEmpty()|| row.SpecValue.IsNullOrEmpty())
continue; continue;
insertSql.Add($"INSERT INTO AGILE_ALGORITHM_CONFIG (GUID, Mode, Spec, Shape, JsonKey, Value)" + 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); finalSaveData.Add(row);
} }
@ -204,6 +234,7 @@ public class AlgorithmConfigVM : BaseViewModel
// 命令实现 // 命令实现
public ICommand AddCommand => new RelayCommand((param) => public ICommand AddCommand => new RelayCommand((param) =>
{ {
string data = GetAlgorithmConfig("P8 P8");
AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak)); AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak));
}); });
@ -341,6 +372,77 @@ public class AlgorithmConfigVM : BaseViewModel
return AlgorithmConfigJson; 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 Header="运行模式" Width="*">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<ComboBox ItemsSource="{Binding ModeList}" <ComboBox ItemsSource="{Binding DataContext.ModeList, RelativeSource={RelativeSource AncestorType=DataGrid}}"
SelectedValue="{Binding Mode.Value}" SelectedValue="{Binding ModeValue, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name" DisplayMemberPath="Name" SelectedValuePath="Value"
SelectedIndex="1" />
SelectedValuePath="Value"/>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
@ -158,12 +157,10 @@
<DataGridTemplateColumn Header="规格" Width="2*"> <DataGridTemplateColumn Header="规格" Width="2*">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<ComboBox ItemsSource="{Binding SpceList}" <ComboBox ItemsSource="{Binding DataContext.SpecList, RelativeSource={RelativeSource AncestorType=DataGrid}}"
SelectedValue="{Binding Spec.Value}" SelectedValue="{Binding SpecValue, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name" DisplayMemberPath="Name" SelectedValuePath="Value"
/>
SelectedIndex="1"
SelectedValuePath="Value"/>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
@ -172,8 +169,9 @@
<DataGridTemplateColumn Header="JSON Key" Width="3*" > <DataGridTemplateColumn Header="JSON Key" Width="3*" >
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<hc:AutoCompleteTextBox IsTextSearchEnabled="True" Text="{Binding JsonKey, Mode=TwoWay}" <hc:AutoCompleteTextBox
ItemsSource="{Binding JsonKeys}" /> Text="{Binding JsonKey, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding RunKey}" />
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>

Loading…
Cancel
Save