public void BubbleSortByParam(int index_of_param, Parametr param) { if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int)) { for (int i = 0; i < Rows.Count; i++) { for (int j = i + 1; j < Rows.Count; j++) { if (Convert.ToDouble(Rows.ElementAt(j)[index_of_param].Value, UsCulture) < Convert.ToDouble(Rows.ElementAt(i)[index_of_param].Value, UsCulture)) { var temp = Rows[i]; Rows[i] = Rows[j]; Rows[j] = temp; } } } } else { for (int i = 0; i < Rows.Count; i++) { for (int j = i + 1; j < Rows.Count; j++) { if (String.Compare(Rows.ElementAt(j)[index_of_param].Value, Rows.ElementAt(i)[index_of_param].Value) < 0) { var temp = Rows[i]; Rows[i] = Rows[j]; Rows[j] = temp; } } } } }
public Parametr GetOneParametrWithRequest(String req) { Parametr res = null; SQLiteCommand cmd = new SQLiteCommand(conn); cmd.Transaction = trans; cmd.CommandText = req; try { SQLiteDataReader r = cmd.ExecuteReader(); string line = String.Empty; res = new Parametr(); Parametr param; while (r.Read()) { param = new Parametr(); param.ID = int.Parse(string.Format("{0}", r["ID"])); param.Number = int.Parse(string.Format("{0}", r["NUMBER"])); param.Range = r["RANGE"].ToString(); param.Type = (TypeParametr)Enum.Parse(typeof(TypeParametr), string.Format("{0}", r["TYPE"])); param.TaskID = int.Parse(string.Format("{0}", r["TASK_ID"])); param.Name = r["NAME"].ToString(); res = param; } r.Close(); } catch (SQLiteException ex) { Console.WriteLine(ex.Message); return(null); } return(res); }
//public static IEnumerable<string[,]> GetDataTables(params IEnumerable[] collections) //{ // if (collections == null) return null; // List<string[,]> array = new List<string[,]>(); // foreach (IEnumerable collection in collections) // array.Add(GetDataTable(collection)); // return array; //} public static string[,] GetDataTable <T>(IEnumerable <T> collection) { if (collection == null || !collection.Any()) { return(new string[0, 0]); } var first = collection.First(); return (first is Meter ? Meter.GetDataTableOfMeters(collection.Cast <Meter>()) : first is Document ? Document.GetDataTableOfDocuments(collection.Cast <Document>()) : first is Parametr ? Parametr.GetDataTableOfParametrs(collection.Cast <Parametr>()) : first is Reading ? Reading.GetDataTableOfReadings(collection.Cast <Reading>()) : first is Tariff ? Tariff.GetDataTableOfTariffs(collection.Cast <Tariff>()) : first is TimeSpan ? TimeSpan.GetDataTableOfTimeSpans(collection.Cast <TimeSpan>()) : first is Type ? Type.GetDataTableOfTypes(collection.Cast <Type>()) : first is User ? User.GetDataTableOfUsers(collection.Cast <User>()) : new string[0, 0]); }
public VeryfiedClassInfo[] ClassInfoInit() { Parametr param = sqlManager.GetOneParametrWithRequest("SELECT * FROM PARAM WHERE( NUMBER = '0' AND TASK_ID = (SELECT TASK_ID FROM SELECTION WHERE NAME = '" + tvTaskSelections.SelectedNode.Text + "'))"); int number_of_out_par = 1; for (int i = 0; i < param.Range.Length; i++) { if (param.Range[i] == '|') { number_of_out_par++; } } VeryfiedClassInfo[] newClassInfo = new VeryfiedClassInfo[number_of_out_par]; for (int i = 0; i < number_of_out_par; i++) { newClassInfo[i] = new VeryfiedClassInfo(); } for (int i = 0, j = 0; i < param.Range.Length; i++) { if (param.Range[i] == '|') { j++; continue; } if (param.Range[i] != ' ') { newClassInfo[j].class_name += param.Range[i]; } } return(newClassInfo); }
/// <summary> /// Автоматическая задача сбора Ip Адресов пляшем от домена поиск и ping /// Задача поиска компьютеров и добавление их в БД /// </summary> public async void FindHostNameIp(object sender, EventArgs e) { await Task.Factory.StartNew(() => { try { Parametr parametr = new Parametr(); DateTime date = DateTime.Now; if (date.Hour == parametr.Hours && date.Minute == parametr.Minutes) { try { PingIp ping = new PingIp(); ping.FindIpHost(parametr.PathDomainComputer, parametr.FindWorkStations); } catch (Exception exception) { Loggers.Log4NetLogger.Error(exception); } } } catch (Exception ex) { Loggers.Log4NetLogger.Error(ex); } }); }
private unsafe void CameraParametrControl_OnParametrEvent(Parametr parametr, int index) { fixed(Parametr *par = &camParametrs.Brightness) { *(par + index) = parametr; } OeipHelper.setDeviceParametrs(cameraId, ref camParametrs); }
public void treeBuilding(EducationTable education_table, TreeNode tree_node) { VeryfiedClassInfo[] thisClassInfo = ClassInfoInit(); for (int i = 0; i < education_table.Rows.Count; i++) { foreach (VeryfiedClassInfo clinf in thisClassInfo) { if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value) { clinf.number_of_checked++; } } } int k = 0; foreach (VeryfiedClassInfo clinf in thisClassInfo) { if (clinf.number_of_checked >= 1) { k++; } } if (k >= 2) { tree_node.is_leaf = false; int index_of_parametr = 0; string best_value_for_split = ""; Parametr param = new Parametr(); FindBetterParametr(education_table, ref index_of_parametr, ref best_value_for_split, ref param); tree_node.rule = new Rule(); tree_node.rule.index_of_param = index_of_parametr; tree_node.rule.value = best_value_for_split; tree_node.left_child = new TreeNode(); tree_node.right_child = new TreeNode(); EducationTable left_table = new EducationTable(); EducationTable right_table = new EducationTable(); SplitEducationTable(education_table, tree_node.rule, param, ref left_table, ref right_table); treeBuilding(left_table, tree_node.left_child); treeBuilding(right_table, tree_node.right_child); } else { tree_node.is_leaf = true; tree_node.rule = new Rule(); foreach (VeryfiedClassInfo clinf in thisClassInfo) { if (clinf.number_of_checked > 0) { tree_node.rule.value = clinf.class_name; } } } }
public void FileBakcup() { Task task = new Task((() => { Parametr param = new Parametr(); using (BakcupingDb bakcuping = new BakcupingDb()) { bakcuping.Backup(param.WorkDB, param.TestDB, param.PathJurnal); } })); task.Start(); }
public void DeleteParametr(int id) { Parametr par = GetParametr(id); foreach (Meter met in par.Meters) { met.Parametrs.Remove(par); } cont.ParametrSet.Remove(par); cont.SaveChanges(); }
//typedef enum tagVideoProcAmpFlags //{ // VideoProcAmp_Flags_Auto = 0x0001, // VideoProcAmp_Flags_Manual = 0x0002, //} //VideoProcAmpFlags; public void InitControl(ref Parametr par, string text, int pindex, bool bCheck = false) { if (par.Flag == 0) { this.trackBar1.Enabled = false; this.textBox1.Enabled = false; this.checkBox1.Enabled = false; } else { this.checkBox1.Checked = par.Flag == 1 ? true : false; this.checkBox1.Enabled = bCheck; } this.label1.Text = text; this.trackBar1.Minimum = par.Min; this.trackBar1.Maximum = par.Max; parametr = par; this.textBox1.Text = parametr.CurrentValue.ToString(); this.trackBar1.Value = parametr.CurrentValue; index = pindex; }
/// <summary> /// Metoda se postara o nacteni vsech zdroju z xml do sceny /// </summary> /// <param name="url">Cesta k xml popisujicimu scenu</param> public void LoadSceneFromXml(String url) { sceneManager.Clear(); Logger.AddInfo("Nacitani data.xml"); data = new DataControl(device, sceneManager.GetSharedPool()); List <Entity> entity = data.LoadXML(url); Type objectType; Object[] par; ConstructorInfo[] constructorInfo; ParameterInfo[] parameters; Assembly asm = Assembly.GetExecutingAssembly(); foreach (Entity obj in entity) { List <Parametr> entityParameters = obj.GetParametrs(); if (obj.Type == "Microsoft.DirectX.Direct3D.Effect") { foreach (Parametr v in entityParameters) { sceneManager.AddEffect(v.name, v.value as Effect); } continue; } objectType = asm.GetType(obj.Type); constructorInfo = objectType.GetConstructors(); List <Object> objPar = new List <object>(); foreach (ConstructorInfo constructor in constructorInfo) { objPar.Clear(); parameters = constructor.GetParameters(); foreach (ParameterInfo param in parameters) { if (param.ParameterType.ToString() == "Microsoft.DirectX.Direct3D.Device") { objPar.Add(device); } else if (param.ParameterType.ToString() == "WiccanRede.Scene.SceneManager") { objPar.Add(sceneManager); } else { Parametr obj2 = obj[param.Name]; if (obj2 != null) { objPar.Add(obj2.value); } else { objPar.Add(null); } } } } par = objPar.ToArray(); Effect shader = null; foreach (Parametr p in entityParameters) { if (p.type == "Microsoft.DirectX.Direct3D.Effect") { shader = p.value as Effect; } else if (p.name.ToLower() == "shader") { shader = sceneManager[p.value as String]; } } String name = obj.Type; if (obj["name"] != null) { name = obj["name"].value as String; } bool shadowEmitter = true; if (obj["shadowEmitter"] != null) { shadowEmitter = (bool)obj["shadowEmitter"].value; } sceneManager.AddObject(name, Activator.CreateInstance(objectType, par) as GeneralObject, shader, shadowEmitter); } }
private byte Convolution(int i, int j, int width, int height, RGB[,] pixels, Kernel kernel, Parametr paramtr) { double sum = 0; for (int k = -kernel.R; k <= kernel.R; k++) { for (int l = -kernel.R; l <= kernel.R; l++) { int parametrValue = 0; switch (paramtr) { case Parametr.R: parametrValue = pixels[GetPixelIndex(i + k, width), GetPixelIndex(j + l, height)].Red; break; case Parametr.G: parametrValue = pixels[GetPixelIndex(i + k, width), GetPixelIndex(j + l, height)].Green; break; case Parametr.B: parametrValue = pixels[GetPixelIndex(i + k, width), GetPixelIndex(j + l, height)].Blue; break; } sum += kernel.Matrix[k + kernel.R, l + kernel.R] * parametrValue; } } return((byte)Math.Round(sum)); }
public void SplitEducationTable(EducationTable education_table, Rule split_rule, Parametr param, ref EducationTable left_table, ref EducationTable right_table) { if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int)) { for (int i = 0; i < education_table.Rows.Count; i++) { double curVal = Convert.ToDouble(education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value, UsCulture); double splitVal = Convert.ToDouble(split_rule.value, UsCulture); if (curVal <= splitVal) { right_table.Rows.Add(education_table.Rows.ElementAt(i)); } else { left_table.Rows.Add(education_table.Rows.ElementAt(i)); } } right_table.ParameterCount = education_table.ParameterCount; left_table.ParameterCount = education_table.ParameterCount; } else { for (int i = 0; i < education_table.Rows.Count; i++) { String curVal = education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value; String splitVal = split_rule.value; if (curVal == splitVal) { right_table.Rows.Add(education_table.Rows.ElementAt(i)); } else { left_table.Rows.Add(education_table.Rows.ElementAt(i)); } } right_table.ParameterCount = education_table.ParameterCount; left_table.ParameterCount = education_table.ParameterCount; } }
public void FindBetterParametr(EducationTable education_table, ref int index_of_parametr, ref string best_value_for_split, ref Parametr _param) { index_of_parametr = 0; best_value_for_split = ""; VeryfiedClassInfo[] leftClassInf = ClassInfoInit(); VeryfiedClassInfo[] rightClassInf = ClassInfoInit(); Parametr param; double giniValue = -100000; for (int index = 1; index < education_table.ParameterCount; index++) { param = sqlManager.GetOneParametrWithRequest("SELECT * FROM PARAM WHERE ID ='" + education_table.Rows.ElementAt(1)[index].ParametrID + "'"); education_table.BubbleSortByParam(index, param); if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int)) { double average = 0; for (int prevRowInd = 1, nextRowInd = 2; nextRowInd < education_table.Rows.Count; prevRowInd++, nextRowInd++) { average = (Convert.ToDouble(education_table.Rows.ElementAt(prevRowInd)[index].Value, UsCulture) + Convert.ToDouble(education_table.Rows.ElementAt(nextRowInd)[index].Value, UsCulture)) / 2.0; for (int i = 0; i < education_table.Rows.Count; i++) { if (Convert.ToDouble(education_table.Rows.ElementAt(i)[index].Value, UsCulture) <= average) { foreach (VeryfiedClassInfo clinf in rightClassInf) { if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value) { clinf.number_of_checked++; } } } else { foreach (VeryfiedClassInfo clinf in leftClassInf) { if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value) { clinf.number_of_checked++; } } } } double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf); if (newGiniValue > giniValue) { giniValue = newGiniValue; index_of_parametr = index; best_value_for_split = average.ToString(UsCulture); _param = param; } for (int i = 0; i < leftClassInf.Length; i++) { leftClassInf[i].number_of_checked = 0; rightClassInf[i].number_of_checked = 0; } } } else { //param.Range int number_of_var = 0; for (int i = 0; i < param.Range.Length; i++) { if (param.Range[i] == '|') { number_of_var++; } } String[] variables = new String[number_of_var + 1]; for (int i = 0, j = 0; i < param.Range.Length; i++) { if (param.Range[i] == '|') { j++; continue; } if (param.Range[i] != ' ') { variables[j] += param.Range[i]; } } for (int j = 0; j < number_of_var; j++) { for (int i = 0; i < education_table.Rows.Count; i++) { if (education_table.Rows.ElementAt(i)[index].Value == variables[j]) { foreach (VeryfiedClassInfo clinf in rightClassInf) { if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value) { clinf.number_of_checked++; } } } else { foreach (VeryfiedClassInfo clinf in leftClassInf) { if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value) { clinf.number_of_checked++; } } } } double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf); if (newGiniValue > giniValue) { giniValue = newGiniValue; index_of_parametr = index; best_value_for_split = variables[j]; _param = param; } for (int i = 0; i < leftClassInf.Length; i++) { leftClassInf[i].number_of_checked = 0; rightClassInf[i].number_of_checked = 0; } } } } }