private static IEnumerable<DataLine> GetDataLinesFrom(string fileName) { IList<DataLine> lines = new List<DataLine>(); using (StreamReader reader = new StreamReader(fileName)) { reader.ReadLine(); while (!reader.EndOfStream) { string line = reader.ReadLine(); if (!string.IsNullOrEmpty(line)) { string[] splits = line.Split(','); DataLine dataLine = new DataLine(); dataLine.Time = double.Parse(splits[0]); dataLine.Speed = double.Parse(splits[5]); dataLine.GForcex = double.Parse(splits[6]); dataLine.GForcey = double.Parse(splits[7]); lines.Add(dataLine); } } } return lines; }
public virtual Catalog AddDataLine(DataLine aLine) { if (!this.lines.Contains(aLine)) { this.lines.Add(aLine); } return this; }
public async Task ReadDataFromStream_AsSeq_Success() { var cts = new CancellationTokenSource(); string source = "123. Apple\n222. Banana"; using (Stream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(source))) { var textProvider = ServiceProvider.GetRequiredService <TextFileDataProvider>(); DataLine dataLine = await textProvider.GetNextLine(memoryStream, cts.Token); Assert.Equal(123, dataLine.Number); Assert.True( StringComparer.InvariantCultureIgnoreCase.Equals("Apple", dataLine.StringData)); dataLine = await textProvider.GetNextLine(memoryStream, cts.Token); Assert.Equal(222, dataLine.Number); Assert.True( StringComparer.InvariantCultureIgnoreCase.Equals("Banana", dataLine.StringData)); } }
/// <summary> /// Calculates the numerical distance between two object using their collected set of values. /// </summary> /// <param name="a">First DataLine</param> /// <param name="b">Second DataLine</param> /// <param name="ignoreLabel">This string label will be ignored in the calculation</param> /// <returns>The distance between the two objects, 0 = identical</returns> private static double CalcDistance(DataLine a, DataLine b, string ignoreLabel) { double strings = a.hashStrings.Keys.Where(k => !k.Equals(ignoreLabel)).Count(s => a.hashStrings[s] == null || !a.hashStrings[s].Equals(b.hashStrings[s])); double doubles = 0.0; double booleans = a.hashBooleans.Keys.Count(k => a.hashBooleans[k] != b.hashBooleans[k]); double stringArrays = 0.0; // doubles foreach (string key in a.hashDoubles.Keys) { if (a.hashDoubles[key] == null || b.hashDoubles[key] == null) { doubles += 1.0; } else { doubles += Math.Abs((double)a.hashDoubles[key] - (double)b.hashDoubles[key]); } } // string arrays foreach (string key in a.hashStringArrays.Keys) { if (a.hashStringArrays[key] == null || b.hashStringArrays[key] == null) { stringArrays += 1.0; } else { var union = a.hashStringArrays[key].Union(b.hashStringArrays[key]); stringArrays += union.Count(s => !a.hashStringArrays[key].Contains(s) || !b.hashStringArrays[key].Contains(s)) / (1.0 * union.Count()); } } return(strings + doubles + booleans + stringArrays); }
public async Task WriteDataIntoStream_Success() { var cts = new CancellationTokenSource(); DataLine line = new DataLine(123, "Apple"); using (Stream stream = new MemoryStream()) { var textProvider = ServiceProvider.GetRequiredService <TextFileDataProvider>(); await textProvider.WriteLine(line, stream, cts.Token); stream.Seek(0, SeekOrigin.Begin); using (TextReader reader = new StreamReader(stream, Encoding.UTF8)) { string stringLine = await reader.ReadLineAsync(); Assert.NotNull(stringLine); Assert.True( StringComparer.InvariantCultureIgnoreCase.Equals( "123. Apple", stringLine)); } } }
public static JsonSaveTypes.Line ToSaveJsonLine(DataLine line) => new JsonSaveTypes.Line { T = line.Target.AsId(), P = ToJsonPoints(line.Points) };
protected override bool ParseSetup() { if (BotBase.ReadBotType(RC) != BotType) { return(false); } List <string> CustomData = RC.CustomData.Trim().Replace("\r\n", "\n").Split('\n').ToList(); foreach (string DataLine in CustomData) { if (DataLine.Contains("EEM_AI")) { continue; } if (DataLine.Contains("Type")) { continue; } var Data = DataLine.Trim().Split(':'); Data[1] = Data[1].Trim(); switch (Data[0].Trim()) { case "Faction": break; case "FleeOnlyWhenDamaged": if (!bool.TryParse(Data[1], out FreighterSetup.FleeOnlyWhenDamaged)) { DebugWrite("ParseSetup", "AI setup error: FleeOnlyWhenDamaged cannot be parsed"); return(false); } break; case "FleeTriggerDistance": if (!float.TryParse(Data[1], out FreighterSetup.FleeTriggerDistance)) { DebugWrite("ParseSetup", "AI setup error: FleeTriggerDistance cannot be parsed"); return(false); } break; case "FleeSpeedRatio": if (!float.TryParse(Data[1], out FreighterSetup.FleeSpeedRatio)) { DebugWrite("ParseSetup", "AI setup error: FleeSpeedRatio cannot be parsed"); return(false); } break; case "FleeSpeedCap": if (!float.TryParse(Data[1], out FreighterSetup.FleeSpeedCap)) { DebugWrite("ParseSetup", "AI setup error: FleeSpeedCap cannot be parsed"); return(false); } break; default: DebugWrite("ParseSetup", $"AI setup error: Cannot parse '{DataLine}'"); return(false); } } FreighterSetup.Default(); return(true); }
private DataLine Parse(IRow data, int index, ItemDefinition definition, List <string> primaryKeys) { var d0 = DateTime.Now; var res = new DataLine() { Line = index, Data = string.Empty }; if (data.Cells.Count > this.typeIndex.Count) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = "El número de celdas no es correcto" }); } else { var message = new StringBuilder("["); int contCell = 0; var itemData = new ItemBuilder(this.Item.ItemName, definition, this.instance.Name); foreach (var field in itemFields) { var cell = data.GetCell(contCell); string cellValue = "null"; string testValue = string.Empty; if (cell != null) { cellValue = GetCellValueForJson(this.typeIndex[contCell], cell, field.Length); testValue = cellValue; // GES-129 Eliminar comillas del inicio y final if (testValue.StartsWith("\"", StringComparison.OrdinalIgnoreCase)) { testValue = testValue.Substring(1); } if (testValue.EndsWith("\"", StringComparison.OrdinalIgnoreCase)) { testValue = testValue.Substring(0, testValue.Length - 1); } // GES-238 los mails y urls deben cumplir el formato if (field.DataType == FieldDataType.Email) { if (field.Required || !string.IsNullOrEmpty(testValue)) { if (!Basics.EmailIsValid(testValue)) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = string.Format( CultureInfo.InvariantCulture, "El email del campo {0} no es valido ({1}).", field.Label, testValue) }); } } } if (field.DataType == FieldDataType.Url) { if (field.Required || !string.IsNullOrEmpty(testValue)) { Uri uriResult; bool result = Uri.TryCreate(testValue, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!result) { testValue = "http://" + testValue; result = Uri.TryCreate(testValue, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!result) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = string.Format( CultureInfo.InvariantCulture, "La dirección URL del campo {0} no es valida ({1}).", field.Label, testValue) }); } } } } if (this.typeIndex[contCell] == FieldDataType.Text || this.typeIndex[contCell] == FieldDataType.Textarea) { if (field.Length.HasValue) { if (testValue.Length > field.Length) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = string.Format( CultureInfo.InvariantCulture, "El campo {0} tiene una longitud superior a {1}.", field.Label, field.Length.Value) }); } } } //// END GES-129 // Sólo se comprueba el FK si el campo está informado if (!string.IsNullOrEmpty(testValue)) { // GES-130 Se comprueba que si es un foreignlist haya valor en la tabla referenciada /*if (definition.ForeignValues.Any(fv => fv.LocalName == field.Name)) * { * ForeignList fl = definition.ForeignValues.Where(fv => fv.LocalName.Equals(field.Name, StringComparison.OrdinalIgnoreCase)).First(); * if (DataPersistence.GetAllByField(Item.InstanceName, fl.ItemName, fl.ImportReference, testValue).Count == 0) * { * errors.Add(new Error() * { * ErrorType = "Data", * Linea = index, * Message = string.Format( * CultureInfo.InvariantCulture, * "El campo <strong>{0}</strong> no encuentra referencia sobre el valor "<strong>{1}</strong>"", * field.Label, * testValue) * }); * } * }*/ } if (cellValue.Equals("\"FixedList\"", StringComparison.OrdinalIgnoreCase)) { string dataCell = cell.StringCellValue; var fixedItem = new FixedListItem();// DataPersistence.FixedListItemGetById(itemData.InstanceName, field.FixedListId, dataCell); if (!string.IsNullOrEmpty(cell.StringCellValue) && fixedItem == null) { errors.Add(new Error() { ErrorType = "Data", Linea = index, Message = string.Format( CultureInfo.InvariantCulture, "El campo <strong>{0}</strong> tiene el valor "<strong>{1}</strong>" que no está en la lista de valores aceptados", field.Label, dataCell) }); } else { itemData[field.Name] = fixedItem.Id; cellValue = string.Format(CultureInfo.InvariantCulture, @"""{0}""", fixedItem.Description); testValue = cellValue.Replace("\"", string.Empty); } } else { if (this.typeIndex[contCell] == FieldDataType.ImageGallery) { itemData.Add(field.Name, string.Empty); testValue = string.Empty; } else if (field.DataType == FieldDataType.Boolean || field.DataType == FieldDataType.NullableBoolean) { if (!string.IsNullOrEmpty(testValue)) { itemData.Add(field.Name, Convert.ToBoolean(testValue)); } } else { if (!string.IsNullOrEmpty(testValue)) { itemData.Add(field.Name, testValue.Replace(@"\""", @"""")); } else { itemData.Add(field.Name, cellValue); } } } } message.AppendFormat(CultureInfo.InvariantCulture, @"{0}""{1}""", contCell > 0 ? "," : string.Empty, testValue); contCell++; } // Juan Castilla - Comprobar que la PK no esté ya en la carga string primaryKeyData = itemData.PrimaryKeyData; if (primaryKeys.Contains(primaryKeyData)) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = "La clave ya aparece en otro registro de esta carga" }); } else { primaryKeys.Add(primaryKeyData); } // Cofirmar que los campos obligatorios están rellenados foreach (var field in Item.Definition.Fields.Where(f => f.Required)) { if (field.Name != "Id" && field.Name != "CompanyId") { if (!itemData.ContainsKey(field.Name)) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = string.Format(CultureInfo.InvariantCulture, "El campo {0} es obligatorio", field.Label) }); } else if (itemData[field.Name] == null) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = "El campo " + field.Label + " es obligatorio" }); } } } if (itemData.Definition.ItemRules.Count > 0) { foreach (var rule in itemData.Definition.ItemRules) { var complains = new SpecialRule(itemData, rule).Complains; if (!complains.Success) { this.errors.Add(new Error() { Linea = index, ErrorType = "Data", Message = complains.MessageError }); } } } message.Append("]"); if (res.Data.Count() < 21) { res.Data = message.ToString(); } this.dataFile.Add(res); this.itemsReaded.Add(itemData); } return(res); }
public bool TryGetSavedLine(NodeName source, NodeName target, out DataLine line) { string lineKey = ((DataNodeName)source).AsId() + ((DataNodeName)target).AsId(); return(savedLines.TryGetValue(lineKey, out line)); }
public bool ParseHeader(IRow header) { var dataHeader = new DataLine() { Line = 0, Data = string.Empty }; var requiredNotFound = new List <string>(); var fileFields = new List <string>(); this.itemFields = new List <ItemField>(); var headerNotField = new List <string>(); var data = new StringBuilder("["); bool firstLabel = true; foreach (ICell cell in header.Cells) { string fieldLabel = cell.ToString().Replace("*", string.Empty); fileFields.Add(fieldLabel); if (this.Item.Definition.Fields.Any(f => f.Label.ToUpperInvariant() == fieldLabel.ToUpperInvariant() && f.Name != "Id")) { if (firstLabel) { firstLabel = false; } else { data.Append(","); } data.AppendFormat(CultureInfo.InvariantCulture, @"""{0}""", ToolsJson.JsonCompliant(fieldLabel)); itemFields.Add(this.Item.Definition.Fields.First(f => f.Label.ToUpperInvariant() == fieldLabel.ToUpperInvariant() && f.Name != "Id" && f.Name != "CompanyId")); } } data.Append("]"); dataHeader.Data = data.ToString(); if (this.dataFile != null) { this.dataFile.Add(dataHeader); } bool errors = false; bool allRequired = true; foreach (var field in this.Item.Definition.Fields.Where(f => f.Required)) { if (field.Name != "Id" && field.Name != "CompanyId") { if (!fileFields.Any(s => s == field.Label)) { allRequired = false; errors = true; requiredNotFound.Add(field.Label); } } } if (!allRequired) { var error = new Error { ErrorType = "Structure", Linea = 0 }; var res = new StringBuilder("Los siguientes campos obligatorios no están en el fichero:"); bool first = true; foreach (string r in requiredNotFound) { if (first) { first = false; } else { res.Append(","); } res.Append(r); } error.Message = res.ToString(); this.errors.Add(error); } bool allHeadersAreFields = true; foreach (string h in fileFields) { if (this.Item.Definition.Fields.Any(f => f.Label == h)) { continue; } allHeadersAreFields = false; headerNotField.Add(h); errors = true; } if (!allHeadersAreFields) { var error = new Error() { ErrorType = "Structure", Linea = 0 }; var res = new StringBuilder(); res.AppendFormat( CultureInfo.InvariantCulture, "Los siguientes datos del fichero no son campos de {0}:", this.Item.Definition.Layout.Label); bool first = true; foreach (string r in headerNotField) { if (first) { first = false; } else { res.Append(","); } res.Append(r); } error.Message = res.ToString(); this.errors.Add(error); } if (!errors) { int contCell = 0; foreach (var field in itemFields) { this.typeIndex.Add(field.DataType); if (field.Required) { this.requiredIndex.Add(contCell); } contCell++; } } return(errors); }
private async Task Run() { try { // Build the C# script if not in CSharp mode if (Config.Mode != ConfigMode.CSharp) { Config.CSharpScript = Config.Mode == ConfigMode.Stack ? Stack2CSharpTranspiler.Transpile(Config.Stack, Config.Settings) : Loli2CSharpTranspiler.Transpile(Config.LoliCodeScript, Config.Settings); } } catch (Exception ex) { await js.AlertException(ex); } if (options.UseProxy && !options.TestProxy.Contains(':')) { await js.AlertError(Loc["InvalidProxy"], Loc["InvalidProxyMessage"]); return; } if (!options.PersistLog) { logger.Clear(); } // Close any previously opened browser if (lastBrowser != null) { await lastBrowser.CloseAsync(); } options.Variables.Clear(); isRunning = true; cts = new CancellationTokenSource(); var sw = new Stopwatch(); var wordlistType = RuriLibSettings.Environment.WordlistTypes.First(w => w.Name == options.WordlistType); var dataLine = new DataLine(options.TestData, wordlistType); var proxy = options.UseProxy ? Proxy.Parse(options.TestProxy, options.ProxyType) : null; var providers = new Providers(RuriLibSettings) { RandomUA = RandomUAProvider, RNG = RNGProvider }; // Build the BotData var data = new BotData(providers, Config.Settings, logger, dataLine, proxy, options.UseProxy); data.CancellationToken = cts.Token; data.Objects.Add("httpClient", new HttpClient()); var runtime = Python.CreateRuntime(); var pyengine = runtime.GetEngine("py"); var pco = (PythonCompilerOptions)pyengine.GetCompilerOptions(); pco.Module &= ~ModuleOptions.Optimized; data.Objects.Add("ironPyEngine", pyengine); var script = new ScriptBuilder() .Build(Config.CSharpScript, Config.Settings.ScriptSettings, PluginRepo); logger.Log($"Sliced {dataLine.Data} into:"); foreach (var slice in dataLine.GetVariables()) { var sliceValue = data.ConfigSettings.DataSettings.UrlEncodeDataAfterSlicing ? Uri.EscapeDataString(slice.AsString()) : slice.AsString(); logger.Log($"{slice.Name}: {sliceValue}"); } logger.NewEntry += OnNewEntry; try { var scriptGlobals = new ScriptGlobals(data, new ExpandoObject()); foreach (var input in Config.Settings.InputSettings.CustomInputs) { (scriptGlobals.input as IDictionary <string, object>).Add(input.VariableName, input.DefaultAnswer); } sw.Start(); var state = await script.RunAsync(scriptGlobals, null, cts.Token); foreach (var scriptVar in state.Variables) { try { var type = DescriptorsRepository.ToVariableType(scriptVar.Type); if (type.HasValue && !scriptVar.Name.StartsWith("tmp_")) { var variable = DescriptorsRepository.ToVariable(scriptVar.Name, scriptVar.Type, scriptVar.Value); variable.MarkedForCapture = data.MarkedForCapture.Contains(scriptVar.Name); options.Variables.Add(variable); } } catch { // The type is not supported, e.g. it was generated using custom C# code and not blocks // so we just disregard it } } } catch (OperationCanceledException) { data.STATUS = "ERROR"; logger.Log($"Operation canceled", LogColors.Tomato); } catch (Exception ex) { data.STATUS = "ERROR"; logger.Log($"[{data.ExecutionInfo}] {ex.GetType().Name}: {ex.Message}", LogColors.Tomato); await js.AlertError(ex.GetType().Name, $"[{data.ExecutionInfo}] {ex.Message}"); } finally { sw.Stop(); isRunning = false; logger.Log($"BOT ENDED AFTER {sw.ElapsedMilliseconds} ms WITH STATUS: {data.STATUS}"); // Save the browser for later use lastBrowser = data.Objects.ContainsKey("puppeteer") && data.Objects["puppeteer"] is Browser currentBrowser ? currentBrowser : null; // Dispose all disposable objects foreach (var obj in data.Objects.Where(o => o.Value is IDisposable)) { if (obj.Key.Contains("puppeteer")) { continue; } try { (obj.Value as IDisposable).Dispose(); } catch { } } } await loggerViewer?.Refresh(); variablesViewer?.Refresh(); await InvokeAsync(StateHasChanged); }
private void button1_Click(object sender, EventArgs e) { List <AxisLineParam> listAxisParam = new List <AxisLineParam>(); CanvasParam canvasparam = new CanvasParam(); Pen p = new Pen(Color.Blue, 1); BufferedGraphics myBuffer = currentContext.Allocate(panel1.CreateGraphics(), panel1.ClientRectangle); Graphics g = myBuffer.Graphics; g.Clear(this.BackColor); this.DoubleBuffered = true; canvasparam.ArrowLength = 6; canvasparam.g = g; canvasparam.OriginX = 43; canvasparam.OriginY = 355; canvasparam.VerticalLength = 350; canvasparam.HorizontalLength = 1000; canvasparam.BlankLegend = 30; canvasparam.ScaleLength = 5; canvasparam.ScalePadding = 0; AxisLineParam bHParam = new AxisLineParam(); bHParam.Direction = LineDirection.Horizontal; bHParam.MaxScale = 100000; bHParam.MinScale = 0; bHParam.CellScale = 10000; bHParam.showVirtualLine = ShowVirtualLine.Visible; bHParam.Caption = "时间(分)"; bHParam.Attributes = "Time"; BaseLine bH = new AxisLine(canvasparam, bHParam); bH.Draw(p); AxisLineParam bVParam = new AxisLineParam(); bVParam.Direction = LineDirection.Vertical; bVParam.showVirtualLine = ShowVirtualLine.Visible; bVParam.MaxScale = 40; bVParam.MinScale = -40; bVParam.CellScale = 10; bVParam.Caption = "温度/℃"; bVParam.Attributes = "Temp"; BaseLine bV = new AxisLine(canvasparam, bVParam); bV.Draw(p); AxisLineParam PowerParam = new AxisLineParam(); PowerParam.Direction = LineDirection.Vertical; PowerParam.showVirtualLine = ShowVirtualLine.Hide; PowerParam.lineLocation = LineLocation.Right; PowerParam.MaxScale = 500; PowerParam.MinScale = 0; PowerParam.CellScale = 100; PowerParam.Caption = "功率"; PowerParam.Attributes = "Power"; PowerParam.Index = 0; BaseLine bPower = new AxisLine(canvasparam, PowerParam); bPower.Draw(p); listAxisParam.Add(bVParam); listAxisParam.Add(bHParam); listAxisParam.Add(PowerParam); DataLine dl = new DataLine(canvasparam, listAxisParam, "Temp"); dl.lineWith = 2; dl.listData = CreateData(Convert.ToInt32(textBox1.Text)); dl.Draw(p); myBuffer.Render(); myBuffer.Dispose(); g.Dispose(); }
public virtual Catalog RemoveDataLine(DataLine aLine) { if (this.lines.Contains(aLine)) { this.lines.Remove(aLine); } return this; }
// Create a new data line for each subscribed measurement private void CreateDataLines(object[] args) { Guid[] subscribedMeasurementIDs; DataLine line; Scale scale; if ((object)args == null || args.Length < 1) return; subscribedMeasurementIDs = args[0] as Guid[]; if ((object)subscribedMeasurementIDs == null || (object)m_scales == null || (object)m_dataLines == null) return; m_scales.Clear(); m_dataLines.Clear(); foreach (Guid measurementID in subscribedMeasurementIDs) { string signalType = "UNKNOWN"; bool autoShrinkScale = false; if ((object)m_measurementMetadata != null) { DataRow[] rows = m_measurementMetadata.Select(string.Format("SignalID = '{0}'", measurementID)); if (rows.Length > 0) { signalType = rows[0]["SignalAcronym"].ToNonNullString(); switch (signalType) { case "IPHM": case "VPHM": case "FREQ": case "ALOG": case "CALC": autoShrinkScale = true; break; } } } line = new DataLine(this, measurementID, m_dataLines.Count); scale = m_scales.GetOrAdd(signalType, type => new Scale(m_graphScale, autoShrinkScale)); scale.Add(line); m_dataLines.TryAdd(measurementID, line); } // Update legend - we do this on a different thread since we've already // waited around for initial set of lines to be created on a UI thread, // no need to keep UI thread operations pending ThreadPool.QueueUserWorkItem(UpdateLegend, subscribedMeasurementIDs); }
public static void FrequentPatternAnalysis() { double support = .05; double confidence = .5; int nbElements = 100000; string[][] data = CSVParser.ReadDataFile("data2014-04-03_03-35-14.csv", ";", null); Console.WriteLine("Read datalines"); DataLine.linkDictionary = CSVParser.ReadLinkFile("linkIdNames.txt"); Console.WriteLine("Read link file"); List <DataLine> answers = DataLine.ParseFixed(data); answers = answers.Take(nbElements).ToList(); var ageList = new List <double>(); var timeList = new HashSet <double>(); var ratingList = new HashSet <double>(); int timeR = 0; foreach (var dl in answers) { var min_age = dl.hashDoubles["min_age"]; if (min_age != null && min_age <= 90) { ageList.Add((double)min_age); } var playingtime = dl.hashDoubles["playingtime"]; if (playingtime != null && playingtime <= 1000) { timeList.Add((double)playingtime); } else { timeR++; } var average_rating = dl.hashDoubles["average_rating"]; if (average_rating != null) { ratingList.Add((double)average_rating); } if (min_age > 90) { Console.WriteLine(dl.hashDoubles["id"] + ": min_age: " + min_age); } if (playingtime > 1000) { Console.WriteLine(dl.hashDoubles["id"] + ": playingtime: " + playingtime); } } /* Console.WriteLine("min_age"); * foreach (var d in ageSet.OrderBy(d => d)) * { * Console.WriteLine("\t" + d); * } * Console.WriteLine("playingtime"); * foreach (var d in timeSet.OrderBy(d => d)) * { * Console.WriteLine("\t" + d); * }*/ var stopwatch = new Stopwatch(); stopwatch.Start(); // Apriori var aprioriLabels = new string[] { "mechanics", "categories", "min_players", "max_players", "playingtime", "average_rating" }; int supportThreshold = (int)(answers.Count * support); Console.WriteLine("Apriori with suppport: " + support); Console.WriteLine("Datalines: " + answers.Count); var patterns = DataMining.Apriori(answers, supportThreshold, aprioriLabels); patterns.Sort((tuple, tuple1) => tuple.Item2 - tuple1.Item2); foreach (Tuple <List <string>, int> list in patterns) { Console.WriteLine("Support: " + list.Item2 + " / " + Math.Round((100d * list.Item2) / answers.Count, 1) + "%: [" + string.Join(",", list.Item1.Select(DataLine.IDtoLabel)) + "]"); } Console.WriteLine("Now doing association mining with confidence: " + confidence); //string aprioriLabel = ""; // Assiciation Rules var ass = DataMining.AprioriAssociationRules(answers, patterns, confidence); ass.Sort((tuple, tuple1) => Math.Sign(tuple.Item4 - tuple1.Item4)); foreach (var cheek in ass) { Console.WriteLine("Conf=" + Math.Round(cheek.Item3 * 100, 1) + "% lift=" + Math.Round(cheek.Item4, 2) + ": [" + string.Join(",", cheek.Item1.Select(DataLine.IDtoLabel)) + "] => \t[" + string.Join(",", cheek.Item2.Select(DataLine.IDtoLabel)) + "]"); } Console.WriteLine("Done with frequent pattern analysis!"); stopwatch.Stop(); Console.WriteLine("Time: " + stopwatch.ElapsedMilliseconds); }
protected override bool ParseSetup() { if (BotBase.ReadBotType(RC) != BotType) { return(false); } List <string> CustomData = RC.CustomData.Trim().Replace("\r\n", "\n").Split('\n').ToList(); foreach (string DataLine in CustomData) { if (DataLine.Contains("EEM_AI")) { continue; } if (DataLine.Contains("Type")) { continue; } var Data = DataLine.Trim().Split(':'); Data[0] = Data[0].Trim(); Data[1] = Data[1].Trim(); switch (Data[0]) { case "Faction": break; case "Preset": FighterSetup.Preset = Data[1]; break; case "DelayedAI": if (!bool.TryParse(Data[1], out FighterSetup.DelayedAIEnable)) { DebugWrite("ParseSetup", "AI setup error: DelayedAI cannot be parsed"); return(false); } break; case "AssignToPirates": if (!bool.TryParse(Data[1], out FighterSetup.AssignToPirates)) { DebugWrite("ParseSetup", "AI setup error: AssignToPirates cannot be parsed"); return(false); } break; case "AttackNeutrals": if (!bool.TryParse(Data[1], out FighterSetup.AttackNeutrals)) { DebugWrite("ParseSetup", "AI setup error: AttackNeutrals cannot be parsed"); return(false); } break; case "AmbushMode": if (!bool.TryParse(Data[1], out FighterSetup.AmbushMode)) { DebugWrite("ParseSetup", "AI setup error: AmbushMode cannot be parsed"); return(false); } break; case "SeekDistance": if (!float.TryParse(Data[1], out FighterSetup.SeekDistance)) { DebugWrite("ParseSetup", "AI setup error: SeekDistance cannot be parsed"); return(false); } break; case "ActivationDistance": if (!float.TryParse(Data[1], out FighterSetup.AIActivationDistance)) { DebugWrite("ParseSetup", "AI setup error: ActivationDistance cannot be parsed"); return(false); } break; case "PlayerPriority": DebugWrite("ParseSetup", "AI setup warning: PlayerPriority is deprecated and no longer used."); break; case "CallHelpProbability": int probability; if (!int.TryParse(Data[1], out probability)) { DebugWrite("ParseSetup", "AI setup error: CallHelpProbability cannot be parsed"); return(false); } else if (probability < 0 || probability > 100) { DebugWrite("ParseSetup", "AI setup error: CallHelpProbability out of bounds. Must be between 0 and 100"); return(false); } else { FighterSetup.CallHelpProbability = probability; } break; case "ThrustMultiplier": float multiplier; if (!float.TryParse(Data[1], out multiplier)) { DebugWrite("ParseSetup", "AI setup error: ThrustMultiplier cannot be parsed"); return(false); } else { ApplyThrustMultiplier(multiplier); } break; default: DebugWrite("ParseSetup", $"AI setup error: Cannot parse '{DataLine}'"); return(false); } } FighterSetup.Default(); return(true); }
public void Empty_Constructor() { DataLine <int> dataLine = new DataLine <int>(); Assert.IsTrue(dataLine.DataUnits.Length == 0); }
public void Add(DataLine line) { m_lines.Add(line); }
void next() { string text = ""; DataLine line = currScript.getNewLine(); if (line != null) { if (line.type == DataLine.Type._choice) { if (line.data.Length > 1) { for (int i = 1; i < line.data.Length; i++) { print("add choice"); } } } else { while (line.type != DataLine.Type._break) { switch (line.type) { case DataLine.Type._sprite: int index = int.Parse(line.data[0]); GameObject charToSet = charInScene[index]; SpriteRenderer sr = charToSet.GetComponent <SpriteRenderer>(); Sprite[] charSprites = Resources.LoadAll <Sprite>("Characters/" + line.data[1]); sr.sprite = GetSpriteByName(charSprites, line.data[2]); Resources.UnloadUnusedAssets(); break; case DataLine.Type._talk: if (currScript.names.ContainsKey(line.data[0])) { namebox.text = currScript.names[line.data[0]]; } else { namebox.text = "Myself"; } break; case DataLine.Type.text: text += line.data[0] + "\n"; break; default: break; } line = currScript.getNewLine(); } textToWrite = text; StopAllCoroutines(); StartCoroutine(writeText()); } } else { //If we are at the end of the script Messenger.Invoke(GameEvent.END_SCENE); } }
public void Empty_String() { DataLine <int> dataLine = new DataLine <int>(""); Assert.IsTrue(dataLine.DataUnits.Length == 0); }
private static double Dissimilarity(DataLine a, KMeanCluster c) { Dictionary <string, double> centroid = c.Centroid; return(centroid.Sum(kv => Math.Abs(a.hashDoubles[kv.Key] ?? 0.0 - kv.Value))); // TODO: null == 0.0 might not be good }
private static bool IsGameNominee(DataLine game, List <DataLine> nominees) { return(nominees.Any(n => n.hashDoubles["game_id"].Equals(game.hashDoubles["id"]))); }
public GccMakefileParser(String MakeFile) { FileInfo fIfoMakeFile = new FileInfo(MakeFile); Root = fIfoMakeFile.Directory; Vars = new SortedList <string, string>(); SourceFiles = new SortedList <string, FileInfo>(); IncludePaths = new SortedList <string, DirectoryInfo>(); LibraryFiles = new SortedList <string, FileInfo>(); Defines = new List <string>(); String[] DataLines = File.ReadAllLines(MakeFile); // // Process all data-lines // foreach (String DataLine in DataLines) { // split makefile lines by spaces => results in words String[] DataItems = DataLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (DataItems.Length > 0) { // // sometimes +=: does not have spaces, so if first word contains +=: which should be in DataItems[1] // replace +=: with " += : " and split again // if (DataItems[0].Contains("+=:")) { String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("+=:", " += :")); DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } // // sometimes += does not have spaces, so if first word contains += which should be in DataItems[1] // replace += with " += " and split again // if (DataItems[0].Contains("+=")) { String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("+=", " += ")); DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } // // sometimes = does not have spaces, so if first word contains = which should be in DataItems[1] // replace = with " = " and split again // else if (DataItems[0].Contains("=")) { String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("=", " = ")); DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } } if (DataItems.Length > 2) { // // check second word is "=" which starts a new variable // if (DataItems[1].Equals("=")) { if (Vars.ContainsKey(DataItems[0])) { Vars.Remove(DataItems[0]); } String Val = DataLine.Substring(DataLine.IndexOf('=') + 1); Vars.Add(DataItems[0], Val.TrimStart()); } // // check second word is "+=" which appends a variable // else if (DataItems[1].Equals("+=")) { if (!Vars.ContainsKey(DataItems[0])) { Vars.Add(DataItems[0], ""); } String Val = DataLine.Substring(DataLine.IndexOf('=') + 1); Vars[DataItems[0]] += " " + Val.TrimStart(); } } } // // Search for source files in the specified VPATH variable // String[] VPATH = Vars["VPATH"].Replace(":", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); String[] SRC = Vars["SRC"].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (String SourceFile in SRC) { foreach (String SearchDir in VPATH) { String absSearchDir = Path.Combine(Root.FullName, SearchDir.Replace("/", "\\")); absSearchDir = Path.GetFullPath((new Uri(absSearchDir)).LocalPath); String checkFilePath = Path.Combine(absSearchDir, SourceFile); if (File.Exists(checkFilePath)) { SourceFiles.Add(SourceFile, new FileInfo(checkFilePath)); break; } } } // // Process include paths // String[] INCLUDES = Vars["INCLUDES"].Split(new String[] { "-I" }, StringSplitOptions.RemoveEmptyEntries); Vars.Add("INCLUDESSTRING", ""); foreach (String Include in INCLUDES) { String IncludePath = Path.Combine(Root.FullName, Include.TrimStart().Replace("/", "\\")); IncludePath = Path.GetFullPath((new Uri(IncludePath)).LocalPath); IncludePaths.Add(Include.TrimStart(), new DirectoryInfo(IncludePath)); Vars["INCLUDESSTRING"] += Include.Trim() + ";"; } // // Process libraries // if (Vars.ContainsKey("LIBS")) { String[] LIBS = Vars["LIBS"].Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries); Vars.Add("LIBSSTRING", ""); foreach (String Lib in LIBS) { String LibPath = Path.Combine(Root.FullName, Lib.TrimStart().Replace("/", "\\")); LibPath = Path.GetFullPath((new Uri(LibPath)).LocalPath); Vars["LIBSSTRING"] += Lib.Trim() + ";"; LibraryFiles.Add(Lib, new FileInfo(LibPath)); } } // // Generate defines string // String[] DEFINES = Vars["DEFINES"].Split(new String[] { "-D" }, StringSplitOptions.RemoveEmptyEntries); Vars.Add("DEFINESSTRING", ""); foreach (String Define in DEFINES) { if (!String.IsNullOrEmpty(Define.Trim())) { Defines.Add(ReplaceVars(Define.Trim())); String DefineVar = ReplaceVars(Define.Trim()); if (DefineVar.Contains("=")) { Vars["DEFINESSTRING"] += DefineVar + ";"; } else { Vars["DEFINESSTRING"] += DefineVar + "=1;"; } } } Vars.Add("CFLAGSSTRING", ReplaceVars(Vars["CFLAGS"])); }
private static double[] PrepareInput(DataLine game) { return(game.hashDoubleArrays.SelectMany(kv => kv.Value).ToArray()); }
private string PrepareLine(DataLine data) => $"{data.Number:D}. {data.StringData}";
public void QueueModelLine(NodeName nodeId, DataLine dataLine) { QueuedNode queuedNode = GetQueuedNode(nodeId); queuedNode.Lines.Add(dataLine); }
public async Task Run() { // Build the C# script if not in CSharp mode if (config.Mode != ConfigMode.CSharp) { config.CSharpScript = config.Mode == ConfigMode.Stack ? Stack2CSharpTranspiler.Transpile(config.Stack, config.Settings) : Loli2CSharpTranspiler.Transpile(config.LoliCodeScript, config.Settings); } if (options.UseProxy && !options.TestProxy.Contains(':')) { throw new InvalidProxyException(options.TestProxy); } if (!options.PersistLog) { logger.Clear(); } // Close any previously opened browser if (lastBrowser != null) { await lastBrowser.CloseAsync(); } options.Variables.Clear(); IsRunning = true; cts = new CancellationTokenSource(); var sw = new Stopwatch(); var wordlistType = RuriLibSettings.Environment.WordlistTypes.First(w => w.Name == options.WordlistType); var dataLine = new DataLine(options.TestData, wordlistType); var proxy = options.UseProxy ? Proxy.Parse(options.TestProxy, options.ProxyType) : null; var providers = new Bots.Providers(RuriLibSettings) { RNG = RNGProvider }; if (!RuriLibSettings.RuriLibSettings.GeneralSettings.UseCustomUserAgentsList) { providers.RandomUA = RandomUAProvider; } // Build the BotData var data = new BotData(providers, config.Settings, logger, dataLine, proxy, options.UseProxy) { CancellationToken = cts.Token }; using var httpClient = new HttpClient(); data.SetObject("httpClient", httpClient); var runtime = Python.CreateRuntime(); var pyengine = runtime.GetEngine("py"); var pco = (PythonCompilerOptions)pyengine.GetCompilerOptions(); pco.Module &= ~ModuleOptions.Optimized; data.SetObject("ironPyEngine", pyengine); data.AsyncLocker = new(); dynamic globals = new ExpandoObject(); var script = new ScriptBuilder() .Build(config.CSharpScript, config.Settings.ScriptSettings, PluginRepo); logger.Log($"Sliced {dataLine.Data} into:"); foreach (var slice in dataLine.GetVariables()) { var sliceValue = data.ConfigSettings.DataSettings.UrlEncodeDataAfterSlicing ? Uri.EscapeDataString(slice.AsString()) : slice.AsString(); logger.Log($"{slice.Name}: {sliceValue}"); } // Initialize resources Dictionary <string, ConfigResource> resources = new(); // Resources will need to be disposed of foreach (var opt in config.Settings.DataSettings.Resources) { try { resources[opt.Name] = opt switch { LinesFromFileResourceOptions x => new LinesFromFileResource(x), RandomLinesFromFileResourceOptions x => new RandomLinesFromFileResource(x), _ => throw new NotImplementedException() }; } catch { logger.Log($"Could not create resource {opt.Name}", LogColors.Tomato); } } // Add resources to global variables globals.Resources = resources; var scriptGlobals = new ScriptGlobals(data, globals); // Set custom inputs foreach (var input in config.Settings.InputSettings.CustomInputs) { (scriptGlobals.input as IDictionary <string, object>).Add(input.VariableName, input.DefaultAnswer); } try { sw.Start(); Started?.Invoke(this, EventArgs.Empty); var state = await script.RunAsync(scriptGlobals, null, cts.Token); foreach (var scriptVar in state.Variables) { try { var type = DescriptorsRepository.ToVariableType(scriptVar.Type); if (type.HasValue && !scriptVar.Name.StartsWith("tmp_")) { var variable = DescriptorsRepository.ToVariable(scriptVar.Name, scriptVar.Type, scriptVar.Value); variable.MarkedForCapture = data.MarkedForCapture.Contains(scriptVar.Name); options.Variables.Add(variable); } } catch { // The type is not supported, e.g. it was generated using custom C# code and not blocks // so we just disregard it } } } catch (OperationCanceledException) { data.STATUS = "ERROR"; logger.Log($"Operation canceled", LogColors.Tomato); } catch (Exception ex) { data.STATUS = "ERROR"; var logErrorMessage = RuriLibSettings.RuriLibSettings.GeneralSettings.VerboseMode ? ex.ToString() : ex.Message; logger.Log($"[{data.ExecutionInfo}] {ex.GetType().Name}: {logErrorMessage}", LogColors.Tomato); IsRunning = false; throw; } finally { sw.Stop(); logger.Log($"BOT ENDED AFTER {sw.ElapsedMilliseconds} ms WITH STATUS: {data.STATUS}"); // Save the browser for later use lastBrowser = data.TryGetObject <Browser>("puppeteer"); // Dispose stuff in data.Objects data.DisposeObjectsExcept(new[] { "puppeteer", "puppeteerPage", "puppeteerFrame" }); // Dispose resources foreach (var resource in resources.Where(r => r.Value is IDisposable) .Select(r => r.Value).Cast <IDisposable>()) { resource.Dispose(); } data.AsyncLocker.Dispose(); } IsRunning = false; Stopped?.Invoke(this, EventArgs.Empty); }
private void OnChanged(object sender, FileSystemEventArgs e) { //FileSystemWatcher.EnableRaisingEvents = false; foreach (string FullPath in System.IO.Directory.GetFiles(Path.GetDirectoryName(e.FullPath))) { try { while (!IsFileReady(System.IO.Directory.GetFiles(Path.GetDirectoryName(e.FullPath)).ToList())) { Thread.Sleep(2000); } DateTime FileNameDateTime = new DateTime(); DateTime FileExtensionDateTime = new DateTime(); DateTime ActualDateTime = new DateTime(); Console.WriteLine("Checking File name and extensions..."); try { if (FileType.Settings.UseFileName && !FileType.Settings.UseFileExtension) { ActualDateTime = DateTime.ParseExact(Path.GetFileNameWithoutExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileName, CultureInfo.InvariantCulture); } if (FileType.Settings.UseFileExtension && !FileType.Settings.UseFileName) { ActualDateTime = DateTime.ParseExact(Path.GetExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileExtension, CultureInfo.InvariantCulture); } if (FileType.Settings.UseFileName && FileType.Settings.UseFileExtension) { FileNameDateTime = DateTime.ParseExact(Path.GetFileNameWithoutExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileName, CultureInfo.InvariantCulture); FileExtensionDateTime = DateTime.ParseExact(Path.GetExtension(FullPath).Replace(FileType.Settings.TextToIgnoreFileName, ""), FileType.Settings.DateTimeFormatFileExtension, CultureInfo.InvariantCulture); ActualDateTime = new DateTime(FileNameDateTime.Year, FileNameDateTime.Month, FileNameDateTime.Day, FileExtensionDateTime.Hour, FileExtensionDateTime.Minute, FileExtensionDateTime.Second); } } catch (Exception exception) { Console.WriteLine("Failed to get a DateTime from file. " + exception.Message); if (eventLog != null) { eventLog.WriteEntry("Failed to get a DateTime from file. " + exception.Message, EventLogEntryType.Error); } } if (FileType.Settings.TruncateTable) { try { DataDAO dataDAO = new DataDAO(CollectionDatabase); dataDAO.TruncateTable(FileType.DatabaseStoredProcedureName); eventLog.WriteEntry("Successfully truncated table " + FileType.DatabaseStoredProcedureName + ".", EventLogEntryType.Information); } catch (Exception exception) { Console.WriteLine("Failed to truncate table " + FileType.DatabaseStoredProcedureName + ". " + exception.Message); if (eventLog != null) { eventLog.WriteEntry("Failed to truncate table " + FileType.DatabaseStoredProcedureName + ". " + exception.Message, EventLogEntryType.Error); } } } string[] AllRowsInFile = File.ReadAllLines(FullPath); if (AllRowsInFile.Count() > 0) { string[] DataRows = AllRowsInFile.Skip(FileType.Headers.Count).ToArray(); foreach (string DataLine in DataRows) { int index = 0; string[] Data = DataLine.Split(FileType.CharacterDelimiter); foreach (Column column in FileType.Columns.OrderBy(x => x.ColumnNumber)) { try { if (!column.Ignore) { if (FileType.Settings.LinkDateTime && FileType.Settings.DateTimeColumn == column.ColumnName) { DateTime linkedDate = DateTime.ParseExact(Data[index], FileType.Settings.DateTimeFormatLinkDate, CultureInfo.InvariantCulture); if (linkedDate != null) { column.ColumnData = linkedDate; } //column.ColumnData = ActualDateTime; } else { column.ColumnData = Data[index]; } if (!column.NotInFile) { index++; } } else //Added { index++; } } catch (Exception exception) { Console.WriteLine("Failed to process row: " + DataLine + " - " + exception.Message); if (eventLog != null) { eventLog.WriteEntry("Failed to process row: LinkDate Format: " + FileType.Settings.DateTimeFormatLinkDate + ": " + DataLine + " - " + exception.Message, EventLogEntryType.Error); } } } if (CollectionDatabase != null) { try { DataDAO dataDAO = new DataDAO(CollectionDatabase); string debugData = ""; /* * foreach(Column column in FileType.Columns) * { * debugData += column.ColumnNumber + ":" + column.ColumnName + ":" + column.DatabaseColumnName + ":" + column.ColumnData + "\n"; * } */ //eventLog.WriteEntry("Attempting data: " + debugData, EventLogEntryType.Warning); dataDAO.Insert(FileType.DatabaseStoredProcedureName, FileType.Columns); } catch (Exception exception) { Console.WriteLine("Failed to insert row: " + DataLine + " - " + exception.Message); if (eventLog != null) { eventLog.WriteEntry("Failed to insert row: " + DataLine + " - " + exception.Message, EventLogEntryType.Error); } } } } } Console.WriteLine("Successfuly processed file: " + FullPath + "!"); if (eventLog != null) { eventLog.WriteEntry("Successfuly processed file: " + FullPath + "!", EventLogEntryType.Information); } } catch (Exception exception) { Console.WriteLine("Failed to prcoess file: " + FullPath + ". " + exception.Message); if (eventLog != null) { eventLog.WriteEntry("Failed to prcoess file: " + FullPath + ". " + exception.Message, EventLogEntryType.Error); } } try { if (File.Exists(Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath))) { File.Delete(Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath)); File.Move(FullPath, Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath)); } else { File.Move(FullPath, Path.GetDirectoryName(FullPath) + @"\Processed\" + Path.GetFileName(FullPath)); } } catch (Exception exception) { Console.WriteLine("Failed to move file to Processed folder: " + FullPath + ". " + exception.Message); if (eventLog != null) { eventLog.WriteEntry("Failed to move file to Processed folder: " + FullPath + ". " + exception.Message, EventLogEntryType.Error); } } } //FileSystemWatcher.EnableRaisingEvents = true; }