public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { NumberParameter offset = args[0] as NumberParameter; NumberParameter scale = args[1] as NumberParameter; SingleSelectParameter mode = args[2] as SingleSelectParameter; bool offsetFirst = mode.Value == 0; TimeSeriesValues ret = new TimeSeriesValues(env.SelectedSequence.Values.ColumnNames); foreach (var pair in env.SelectedSequence.Values.Enumerate()) { decimal?[] row = new decimal?[pair.Value.Length]; for (int i = 0; i < row.Length; i++) { decimal?tmp = pair.Value[i]; if (tmp.HasValue) { if (offsetFirst) { tmp = tmp.Value + offset.Value; } tmp = tmp.Value * scale.Value; if (!offsetFirst) { tmp = tmp.Value + offset.Value; } } row[i] = tmp; } ret[pair.Key] = row; } return(new SequenceData(ret, null, PathEx.GiveName("OffsetScale", env.SelectedSequence.Title))); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { SequenceMultiSelectParameter others = args[0] as SequenceMultiSelectParameter; List <TimeSeriesValues> sequences = new List <TimeSeriesValues>(); sequences.Add(env.SelectedSequence.Values); sequences.AddRange(others.Value.Select(d => d.Values)); List <string> columnNames = new List <string>(); int sequenceIndex = 0; foreach (TimeSeriesValues sequence in sequences) { sequenceIndex++; foreach (string name in sequence.ColumnNames) { columnNames.Add(string.Format("{0}.{1}", sequenceIndex, name)); } } TimeSeriesValues values = new TimeSeriesValues(columnNames); foreach (var pair in TimeSeriesValuesCalculation.EnumerateCompositeSequences(sequences)) { values[pair.Key] = pair.Value; } return(new SequenceData(values, null, PathEx.GiveName("Composite", new string[] { env.SelectedSequence.Title }.Union(others.Value.Select(d => d.Title))))); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { TimeSeriesValues values = new TimeSeriesValues(env.SelectedSequence.Values.ColumnNames); foreach (var pair in env.SelectedSequence.Values.Enumerate()) { decimal?[] tmp = new decimal?[env.SelectedSequence.Values.ColumnCount]; if (pair.Value.All(x => x.HasValue)) { try { decimal sum = pair.Value.Sum(x => x.Value); if (sum != 0) { for (int i = 0; i < tmp.Length; i++) { tmp[i] = pair.Value[i].Value / sum; } } } catch (OverflowException) { tmp = new decimal?[env.SelectedSequence.Values.ColumnCount]; } } values.SetValue(pair.Key, tmp); } SequenceData ret = new SequenceData(values, null, PathEx.GiveName("Normal", env.SelectedSequence.Title)); ret.Type = SequenceType.Numeric; return(ret); }
public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo) { TimeSeriesValues values = new TimeSeriesValues("length"); foreach (ReadOnlyMotionFrame frame in frames) { IList <LineObject> lines = selected.Select(info => frame[info] as LineObject).ToList(); if (lines.All(line => line != null) && lines.Count > 0) { try { values.SetValue(frame.Time, (decimal)lines.Sum(line => line.Length())); } catch (ArithmeticException) { values.SetValue(frame.Time, null); } } else { values.SetValue(frame.Time, null); } } string name = selected[0].Name; if (selected.Count > 1) { name += "-etc"; } SequenceData data = new SequenceData(values, null, PathEx.GiveName("Length", name)); return(new SequenceData[] { data }); }
public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo) { List <SequenceData> ret = new List <SequenceData>(); foreach (MotionObjectInfo info in selected) { TimeSeriesValues values = new TimeSeriesValues("x", "y", "z"); foreach (var frame in frames) { LineObject line = frame[info] as LineObject; if (line != null) { try { values[frame.Time] = new decimal?[] { (decimal)line.Edge.X, (decimal)line.Edge.Y, (decimal)line.Edge.Z }; } catch (ArithmeticException) { values[frame.Time] = null; } } else { values[frame.Time] = null; } } SequenceData data = new SequenceData(values, null, PathEx.GiveName("Dir", info.Name)); ret.Add(data); } return(ret); }
public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo) { List <SequenceData> ret = new List <SequenceData>(); foreach (MotionObjectInfo info in selected) { TimeSeriesValues values = new TimeSeriesValues("area"); foreach (var frame in frames) { PlaneObject sphere = frame[info] as PlaneObject; if (sphere != null) { try { values[frame.Time] = new decimal?[] { sphere.GetDimensions() }; } catch (ArithmeticException) { values[frame.Time] = null; } } else { values[frame.Time] = null; } } SequenceData data = new SequenceData(values, null, PathEx.GiveName("Area", info.Name)); ret.Add(data); } return(ret); }
public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo) { MotionObjectSingleSelectParameter main = args[0] as MotionObjectSingleSelectParameter; SingleSelectParameter unit = args[1] as SingleSelectParameter; bool useRatio = unit.Value == 0; MotionObjectInfo firstAxis = main.Value; MotionObjectInfo secondAxis = selected.Where(info => info.IsTypeOf(typeof(LineObject)) && info != firstAxis).First(); IList <MotionObjectInfo> pointInfoList = selected.Where(info => info.IsTypeOf(typeof(PointObject))).ToList(); List <SequenceData> ret = new List <SequenceData>(); foreach (MotionObjectInfo pointInfo in pointInfoList) { TimeSeriesValues values = new TimeSeriesValues("axis1", "axis2", "axis3"); foreach (var frame in frames) { PointObject point = frame[pointInfo] as PointObject; LineObject line1 = frame[firstAxis] as LineObject; LineObject line2 = frame[secondAxis] as LineObject; decimal?[] relValues = null; if (point != null && line1 != null && line2 != null) { Vector3 anchor = line1.Position; Vector3 pointRelPos = point.Position - anchor; Vector3 axis1 = line1.Edge; Vector3 axis2 = line2.Edge; Vector3 axis1norm = Vector3.Normalize(axis1); Vector3 axis2norm = Vector3.Normalize(axis2); Vector3 axis3 = Vector3.Cross(axis1norm, axis2norm) * (float)Math.Sqrt(axis1.Length() * axis2.Length()); if (!useRatio) { axis1 = Vector3.Normalize(axis1); axis2 = Vector3.Normalize(axis2); axis3 = Vector3.Normalize(axis3); } float[,] mat = new float[, ] { { axis1.X, axis2.X, axis3.X }, { axis1.Y, axis2.Y, axis3.Y }, { axis1.Z, axis2.Z, axis3.Z } }; float[] vec = new float[] { pointRelPos.X, pointRelPos.Y, pointRelPos.Z }; SimultaneousEquations solve = SimultaneousEquations.Solve(mat, vec); if (solve.Answers.Length == 3) { relValues = new decimal?[3]; try { relValues[0] = (decimal)solve.Answers[0]; relValues[1] = (decimal)solve.Answers[1]; relValues[2] = (decimal)solve.Answers[2]; } catch (OverflowException) { relValues = null; } } } values.SetValue(frame.Time, relValues); } SequenceData data = new SequenceData(values, null, PathEx.GiveName("RelPos", pointInfo.Name)); ret.Add(data); } return(ret); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { SequenceColumnMultiSelectParameter si = args[0] as SequenceColumnMultiSelectParameter; List <int> indices = si.Value.Where(i => 0 <= i && i < env.SelectedSequence.Values.ColumnNames.Length).ToList(); TimeSeriesValues val = new TimeSeriesValues(indices.Select(i => env.SelectedSequence.Values.ColumnNames[i])); foreach (var pair in env.SelectedSequence.Values.Enumerate()) { val.SetValue(pair.Key, indices.Select(i => pair.Value[i]).ToArray()); } SequenceData ret = new SequenceData(val, new LabelingBorders(env.SelectedSequence.Borders), PathEx.GiveName("Extracted", env.SelectedSequence.Title)); ret.Type = SequenceType.Numeric; return(ret); }
public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo) { SingleSelectParameter unit = args[0] as SingleSelectParameter; bool degree = unit.Value == 0; MotionObjectInfo info1 = selected[0]; MotionObjectInfo info2 = selected[1]; TimeSeriesValues values = new TimeSeriesValues(degree ? "degree" : "radian"); foreach (ReadOnlyMotionFrame frame in frames) { LineObject line1 = frame[info1] as LineObject; LineObject line2 = frame[info2] as LineObject; if (line1 != null && line2 != null) { float cos = Vector3.Dot(line1.Direction(), line2.Direction()); double radian = 0; if (cos <= -1) { radian = Math.PI; } else if (cos < 1) { radian = Math.Acos(cos); } if (degree) { values.SetValue(frame.Time, (decimal)(radian * 180 / Math.PI)); } else { values.SetValue(frame.Time, (decimal)radian); } } else { values.SetValue(frame.Time, null); } } SequenceData data = new SequenceData(values, null, PathEx.GiveName("Angle", info1.Name, info2.Name)); return(new SequenceData[] { data }); }
private void openSequenceForm(TimeSeriesValues sequence, string title) { SequenceViewerForm form = SequenceViewerForm.Singleton; if (!form.Visible) { form.AttachIPluginHost(_pluginHost); try { Script.ScriptConsole.Singleton.MotionDataSet = _dataSet; Script.ScriptConsole.Singleton.ParentControl = this; Script.ScriptConsole.Singleton.Invoke(new Misc.FunctionOpenSequenceViewer(), null); } catch (Exception) { SequenceViewerForm.Singleton.Show(); } } form.BringToFront(); form.AutoLoadSequence(sequence, title); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { SequenceSingleSelectParameter operand = args[0] as SequenceSingleSelectParameter; TimeSeriesValues ret = new TimeSeriesValues("InnerProduct"); int count = Math.Min(env.SelectedSequence.Values.ColumnCount, operand.Value.Values.ColumnCount); using (IEnumerator <KeyValuePair <decimal, decimal?[]> > one = env.SelectedSequence.Values.Enumerate().GetEnumerator()) using (IEnumerator <KeyValuePair <decimal, decimal?[]> > another = operand.Value.Values.Enumerate().GetEnumerator()) { bool oneAlive = one.MoveNext(); bool anotherAlive = another.MoveNext(); while (oneAlive && anotherAlive) { decimal?value = 0; for (int i = 0; i < count; i++) { if (one.Current.Value[i].HasValue && another.Current.Value[i].HasValue) { value = value.Value + one.Current.Value[i].Value * another.Current.Value[i].Value; } else { value = null; break; } } // 後にある時刻のところに値を入れる // 前にある方を進める if (one.Current.Key < another.Current.Key) { ret.SetValue(another.Current.Key, value); oneAlive = one.MoveNext(); } else { ret.SetValue(one.Current.Key, value); anotherAlive = another.MoveNext(); } } } return(new SequenceData(ret, null, PathEx.GiveName("InnerProduct", env.SelectedSequence.Title, operand.Value.Title))); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { var row = ((SequenceSingleSelectParameter)args[0]).Value; var labels = ((LabelSelectParameter)args[1]).Value; TimeSeriesValues newSeq = new TimeSeriesValues(env.SelectedSequence.Values.ColumnNames); foreach (var label in row.GetLabelSequence().EnumerateLabels()) { newSeq.SetValue(label.BeginTime, new decimal?[env.SelectedSequence.Values.ColumnCount]); newSeq.SetValue(label.EndTime, new decimal?[env.SelectedSequence.Values.ColumnCount]); } foreach (var pair in env.SelectedSequence.Values.Enumerate()) { if (labels.Contains(row.GetLabelAt(pair.Key))) { newSeq.SetValue(pair.Key, pair.Value); } } SequenceData ret = new SequenceData(newSeq, new LabelingBorders(env.SelectedSequence.Borders), PathEx.GiveName("ClipBy", new string[] { env.SelectedSequence.Title }.Union(labels))); ret.Type = SequenceType.Numeric; return(ret); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { ICSLabelSequence labelSequence = env.SelectedSequence.GetLabelSequence(); if (labelSequence == null) { MessageBox.Show("ラベルが空でした", this.GetType().ToString()); return(null); } if (env.Controller.WholeEndTime > 0) { labelSequence.SetLabel(0, env.Controller.WholeEndTime, "", true); } TimeSeriesValues sequence = new TimeSeriesValues("value"); Dictionary <string, int> indexInfo = new Dictionary <string, int>(); var labelTexts = labelSequence.GetLabelTexts(true); int count = 0; foreach (var labelText in labelTexts) { indexInfo[labelText] = count; count++; } sequence.SetValue(0, new decimal?[1]); sequence.SetValue(labelSequence.Duration, new decimal?[1]); foreach (var label in labelSequence.EnumerateLabels()) { var value = new decimal?[1] { indexInfo[label.LabelText] }; sequence.SetValue(label.BeginTime, value); } SequenceData ret = new SequenceData(sequence, null, PathEx.GiveName("labelNum", env.SelectedSequence.Title)); ret.Type = SequenceType.Numeric; return(ret); }
public void AutoLoadSequence(TimeSeriesValues sequence, string title) { _viewerController.OpenTimeSeriesValues(sequence, title); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { SingleSelectParameter mode = args[0] as SingleSelectParameter; Func <decimal?, decimal?> ope = new Func <decimal?, decimal?>(x => x); string title = ""; switch (mode.Value) { case 0: ope = x => x.HasValue ? x * x : null; title = "Sq"; break; case 1: ope = x => x.HasValue ? (decimal?)Math.Sqrt((double)x.Value) : null; title = "Sqrt"; break; case 2: ope = x => x.HasValue ? -x : null; title = "Neg"; break; case 3: ope = x => x.HasValue && x.Value != 0 ? (decimal?)1M / x.Value : null; title = "Inv"; break; case 4: ope = x => x.HasValue ? (decimal?)Math.Sin((double)x.Value) : null; title = "Sin"; break; case 5: ope = x => x.HasValue ? (decimal?)Math.Cos((double)x.Value) : null; title = "Cos"; break; case 6: ope = x => x.HasValue ? (decimal?)Math.Tan((double)x.Value) : null; title = "Tan"; break; case 7: ope = x => x.HasValue && -1M <= x.Value && x.Value <= 1M ? (decimal?)Math.Asin((double)x.Value) : null; title = "Asin"; break; case 8: ope = x => x.HasValue && -1M <= x.Value && x.Value <= 1M ? (decimal?)Math.Acos((double)x.Value) : null; title = "Acos"; break; case 9: ope = x => x.HasValue ? (decimal?)Math.Atan((double)x.Value) : null; title = "Atan"; break; case 10: ope = x => x.HasValue ? (decimal?)Math.Exp((double)x.Value) : null; title = "Exp"; break; case 11: ope = x => x.HasValue && x.Value > 0M ? (decimal?)Math.Log((double)x.Value) : null; title = "Log"; break; } TimeSeriesValues ret = new TimeSeriesValues(env.SelectedSequence.Values.ColumnNames.Select(n => title + " " + n).ToArray()); foreach (var pair in env.SelectedSequence.Values.Enumerate()) { decimal?[] row = new decimal?[ret.ColumnCount]; for (int i = 0; i < row.Length; i++) { try { row[i] = ope(pair.Value[i]); } catch (ArithmeticException) { } } ret[pair.Key] = row; } return(new SequenceData(ret, null, PathEx.GiveName(title, env.SelectedSequence.Title))); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { BooleanParameter useAvg = args[0] as BooleanParameter; BooleanParameter useStddev = args[1] as BooleanParameter; TimeSeriesValues ret = new TimeSeriesValues(env.SelectedSequence.Values.ColumnNames); decimal[] avg = new decimal[ret.ColumnCount]; decimal[] stddev = new decimal[ret.ColumnCount]; int[] count = new int[ret.ColumnCount]; foreach (var pair in env.SelectedSequence.Values.Enumerate()) { for (int i = 0; i < ret.ColumnCount; i++) { if (pair.Value[i].HasValue) { avg[i] += pair.Value[i].Value; count[i]++; } } } for (int i = 0; i < ret.ColumnCount; i++) { if (count[i] > 0) { avg[i] /= count[i]; } } foreach (var pair in env.SelectedSequence.Values.Enumerate()) { for (int i = 0; i < ret.ColumnCount; i++) { if (pair.Value[i].HasValue) { decimal diff = pair.Value[i].Value - avg[i]; stddev[i] += diff * diff; } } } for (int i = 0; i < ret.ColumnCount; i++) { if (count[i] > 0) { stddev[i] = (decimal)Math.Sqrt((double)(stddev[i] / count[i])); } } foreach (var pair in env.SelectedSequence.Values.Enumerate()) { decimal?[] row = new decimal?[ret.ColumnCount]; for (int i = 0; i < ret.ColumnCount; i++) { decimal?value = pair.Value[i]; if (value.HasValue) { if (useAvg.Value) { value = value.Value - avg[i]; } if (useStddev.Value && stddev[i] != 0) { value = value.Value / stddev[i]; } } row[i] = value; } ret[pair.Key] = row; } return(new SequenceData(ret, null, PathEx.GiveName("Std", env.SelectedSequence.Title))); }
public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env) { var arith = args[0] as SingleSelectParameter; var operand = args[1] as SequenceMultiSelectParameter; string opText = "null"; TimeSeriesValues result = env.SelectedSequence.Values; string second = ""; foreach (var sequence in operand.Value) { if (second == "") { second = sequence.Title; } else { second += "-etc"; } var operandData = sequence; switch (arith.Value) { case 0: result = TimeSeriesValuesCalculation.OperateWith(result, operandData.Values, (x, y) => x + y); opText = "Add"; break; case 1: result = TimeSeriesValuesCalculation.OperateWith(result, operandData.Values, (x, y) => x - y); opText = "Subtract"; break; case 2: result = TimeSeriesValuesCalculation.OperateWith(result, operandData.Values, (x, y) => x * y); opText = "Multiply"; break; case 3: result = TimeSeriesValuesCalculation.OperateWith(result, operandData.Values, (x, y) => y == 0 ? null : x / y); opText = "Divide"; break; case 4: result = TimeSeriesValuesCalculation.OperateWith(result, operandData.Values, (x, y) => x > y ? x : y); opText = "Max"; break; case 5: result = TimeSeriesValuesCalculation.OperateWith(result, operandData.Values, (x, y) => x < y ? x : y); opText = "Min"; break; default: result = new TimeSeriesValues(); break; } } SequenceData ret = new SequenceData(result, null, PathEx.GiveName(opText, env.SelectedSequence.Title, second)); ret.Type = SequenceType.Numeric; return(ret); }