Beispiel #1
0
        public void GetEnumerator_ShouldReturnAllItemsInOrder(
            DoubleList <object> sut,
            object item,
            object secondaryItem)
        {
            //arrange
            sut.SecondaryList.Add(secondaryItem);
            sut.Add(item);

            //act
            var actual = new List <object>();

            foreach (var i in sut)
            {
                actual.Add(i);
            }

            //assert
            var expected = new List <object>()
            {
                item, secondaryItem
            };

            actual.ShouldAllBeEquivalentTo(expected);
        }
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
/*AUTO SCRIPT*/ {
/*AUTO SCRIPT*/ if (list == null)
/*AUTO SCRIPT*/ {
/*AUTO SCRIPT*/ list  = EditorUtility.GetPropertyObject <DoubleList>(property);
/*AUTO SCRIPT*/ rList = new ReorderableList(list, typeof(double), true, false, true, true);
/*AUTO SCRIPT*/                         // rList.onAddCallback += data => { list.Add(defaultVal); };
/*AUTO SCRIPT*/                         // rList.onChangedCallback += data=> {
/*AUTO SCRIPT*/                         // };
/*AUTO SCRIPT*/ }
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/ numLines = 3 + list.Count;
/*AUTO SCRIPT*/ var title  = new GUIContent($" {label.text}");
/*AUTO SCRIPT*/ var height = base.GetPropertyHeight(property, label);
/*AUTO SCRIPT*/ var rect   = new Rect(position.x, position.y, position.width, height);

/*AUTO SCRIPT*/ EditorGUI.BeginChangeCheck();
/*AUTO SCRIPT*/ rList.DoList(rect);
/*AUTO SCRIPT*/ EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), title);
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/ if (EditorGUI.EndChangeCheck())
            {
/*AUTO SCRIPT*/ property.serializedObject.ApplyModifiedProperties();
            }
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/ }
Beispiel #3
0
        public static void DisplayResult()
        {
            DoubleList <int> linkedList = new DoubleList <int>();

            CreateList(ref linkedList);
            DisplayList(linkedList, true);
        }
Beispiel #4
0
        public void DoubleList_RemoveFromEnd()
        {
            var list = new DoubleList();

            list.AddToFront(new V(0));
            list.Remove(list[0]);
            Assert.AreEqual(0, list.Count);

            list.AddToFront(new V(2));
            list.AddToFront(new V(1));
            list.AddToFront(new V(0));
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);
            Assert.AreEqual(1, ((V)list[1]).Value);
            Assert.AreEqual(2, ((V)list[2]).Value);

            list.Remove(list[2]);
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);
            Assert.AreEqual(1, ((V)list[1]).Value);

            list.Remove(list[1]);
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);

            list.Remove(list[0]);
            Assert.AreEqual(0, list.Count);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            // connect to the grid
            var           engine  = new VelocityEngine();
            Action <bool> orThrow = result => OrThrow(result, engine);

            //orThrow(engine.loginToGrid(USER, PASS, GRID_IP, GRID_PORT, GRID_DB));
            orThrow(engine.loginToWorkstation(USER, PASS, WORKSTATION_PATH, true));
            AppDomain.CurrentDomain.ProcessExit += (source, data) => { engine.logout(); };

            orThrow(engine.loadPatientByPatientId(PATIENT_ID));
            Console.WriteLine("Loaded patient: {0}", PATIENT_ID);
            orThrow(engine.loadPrimaryVolumeByUID(PRIMARY_UID));
            Console.WriteLine("Loaded primary volume: {0}", PRIMARY_UID);
            orThrow(engine.loadSecondaryVolumeByUID(SECONDARY_UID));
            Console.WriteLine("Loaded secondary volume: {0}", SECONDARY_UID);

            // load registration
            ValidOrThrow(engine.loadRegistrationByName(REG_NAME), engine);
            Console.WriteLine("Loaded registration: {0}", REG_NAME);

            var structure = engine.loadStructureByName(STRUCT_1, STRUCTSET_1UID);

            ValidOrThrow(structure, engine);
            Console.WriteLine("Loading existing structure: {0}", STRUCT_1);

            var structNames          = new StringList(new string[] { STRUCT_1 });
            var structAlphaBetaRatio = new DoubleList(new double[] { 2, DEFAULT_ALPHABETA_TISSUE });
            var structUIDs           = new StringList(new string[] { structure.getInstanceUID() });

            var vo = engine.getVolumeOperations();

            OrThrow(vo.createBEDoseByStructureUIDs(25, structNames, structUIDs, structAlphaBetaRatio) != -1, vo);
            Console.WriteLine("Biological Effective Dose created");
        }
Beispiel #6
0
        public void DoubleListAddTestMethod()
        {
            DoubleList <Worker> list = new DoubleList <Worker>();

            list.Add(new Worker("da", "net", 12, "fire"));
            Assert.IsNotNull(list);
        }
Beispiel #7
0
 public DoubleListEnumerator(DoubleList collection)
 {
     collectionRef = collection;
     currentIndex  = -1;
     currentObject = null;
     currentSize   = collectionRef.Count;
 }
Beispiel #8
0
 public DoubleList(DoubleList other) : this(LandmarkDetectorPINVOKE.new_DoubleList__SWIG_1(DoubleList.getCPtr(other)), true)
 {
     if (LandmarkDetectorPINVOKE.SWIGPendingException.Pending)
     {
         throw LandmarkDetectorPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #9
0
        public void DoubleListAreEqualTestMethod()
        {
            Worker WRK      = new Worker("da", "net", 12, "fire");
            Worker WRKSec   = new Worker("net", "da", 22, "ice");
            Worker WRKThird = new Worker("aga", "no", 16, "hot");
            Worker WRKFour  = new Worker("nea", "ofc", 29, "cold");
            Worker WRKFive  = new Worker("nine", "ya", 90, "zero");
            Worker WRKSix   = new Worker("night", "yes", 20, "temperature");

            DoubleList <Worker> dblTestList = new DoubleList <Worker>();

            dblTestList.Add(WRK);
            dblTestList.Add(WRKSec);
            dblTestList.Add(WRKThird);
            dblTestList.Add(WRKFour);
            dblTestList.Add(WRKFive);
            dblTestList.Add(WRKSix);
            int i = 1;

            foreach (Person item in dblTestList)
            {
                Console.WriteLine(i + item.Show());
                i++;
            }
            int j = 1;

            foreach (Person item in dblTestList.FindUnEven())
            {
                Console.WriteLine(j + item.Show());
                j++;
            }
            j--;
            Assert.AreEqual(9, j);
        }
Beispiel #10
0
        public void DoubleList_RemoveAt()
        {
            var list = new DoubleList();
            V   v;

            v = new V(0);
            list.AddToFront(v);
            list.RemoveAt(0);
            Assert.AreEqual(0, list.Count);
            list.AddToEnd(v);
            Assert.AreEqual(1, list.Count);
            list.Clear();

            list.AddToFront(new V(2));
            list.AddToFront(new V(1));
            list.AddToFront(new V(0));
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);
            Assert.AreEqual(1, ((V)list[1]).Value);
            Assert.AreEqual(2, ((V)list[2]).Value);

            list.RemoveAt(1);
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);
            Assert.AreEqual(2, ((V)list[1]).Value);
        }
Beispiel #11
0
        public void DoubleList_Insert()
        {
            var list = new DoubleList();

            Assert.AreEqual(0, list.Count);
            list.InsertAfter(null, new V(0));
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);

            list.InsertAfter(list[list.Count - 1], new V(1));
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);
            Assert.AreEqual(1, ((V)list[1]).Value);

            list.InsertAfter(list[list.Count - 1], new V(2));
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(0, ((V)list[0]).Value);
            Assert.AreEqual(1, ((V)list[1]).Value);
            Assert.AreEqual(2, ((V)list[2]).Value);

            list.InsertAfter(null, new V(3));
            Assert.AreEqual(4, list.Count);
            Assert.AreEqual(3, ((V)list[0]).Value);
            Assert.AreEqual(0, ((V)list[1]).Value);
            Assert.AreEqual(1, ((V)list[2]).Value);
            Assert.AreEqual(2, ((V)list[3]).Value);

            list.InsertAfter(list[0], new V(4));
            Assert.AreEqual(5, list.Count);
            Assert.AreEqual(3, ((V)list[0]).Value);
            Assert.AreEqual(4, ((V)list[1]).Value);
            Assert.AreEqual(0, ((V)list[2]).Value);
            Assert.AreEqual(1, ((V)list[3]).Value);
            Assert.AreEqual(2, ((V)list[4]).Value);
        }
 /**
  * Collects values from a single argument
  */
 private void CollectValues(ValueEval operand, DoubleList temp)
 {
     if (operand is AreaEval)
     {
         AreaEval ae     = (AreaEval)operand;
         int      width  = ae.Width;
         int      height = ae.Height;
         for (int rrIx = 0; rrIx < height; rrIx++)
         {
             for (int rcIx = 0; rcIx < width; rcIx++)
             {
                 ValueEval ve = ae.GetRelativeValue(rrIx, rcIx);
                 CollectValue(ve, true, temp);
             }
         }
         return;
     }
     if (operand is RefEval)
     {
         RefEval re = (RefEval)operand;
         CollectValue(re.InnerValueEval, true, temp);
         return;
     }
     CollectValue((ValueEval)operand, false, temp);
 }
Beispiel #13
0
        public override async Task <EvaluateDoublesReply> EvaluateDoubles(EvaluateDoublesRequest request, ServerCallContext context)
        {
            await _semaphoreSlim.WaitAsync();

            var reply = new EvaluateDoublesReply();

            try
            {
                var doubles = ROpsApi.EvaluateDoubles(request.Code);

                reply.Payload = new EvaluateDoublesPayload();

                foreach (var kvp in doubles)
                {
                    var doubleList = new DoubleList();
                    if (kvp.Value.IsCollection())
                    {
                        doubleList.Doubles.Add(kvp.Value);
                    }
                    reply.Payload.Doubles.Add(kvp.Key, doubleList);
                }
            }
            catch (Exception ex)
            {
                reply.Error = PopulateError(ex);
                _logger.LogError(ex, nameof(EvaluateDoubles));
            }
            finally
            {
                _semaphoreSlim.Release();
            }

            return(await Task.FromResult(reply));
        }
 /**
  * Collects values from a single argument
  */
 private void CollectValues(ValueEval operand, DoubleList temp)
 {
     if (operand is TwoDEval)
     {
         TwoDEval ae     = (TwoDEval)operand;
         int      width  = ae.Width;
         int      height = ae.Height;
         for (int rrIx = 0; rrIx < height; rrIx++)
         {
             for (int rcIx = 0; rcIx < width; rcIx++)
             {
                 ValueEval ve = ae.GetValue(rrIx, rcIx);
                 if (!IsSubtotalCounted && ae.IsSubTotal(rrIx, rcIx))
                 {
                     continue;
                 }
                 CollectValue(ve, true, temp);
             }
         }
         return;
     }
     if (operand is RefEval)
     {
         RefEval re = (RefEval)operand;
         CollectValue(re.InnerValueEval, true, temp);
         return;
     }
     CollectValue((ValueEval)operand, false, temp);
 }
Beispiel #15
0
 public void SetRange(int index, DoubleList values)
 {
     LandmarkDetectorPINVOKE.DoubleList_SetRange(swigCPtr, index, DoubleList.getCPtr(values));
     if (LandmarkDetectorPINVOKE.SWIGPendingException.Pending)
     {
         throw LandmarkDetectorPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #16
0
        private void AddToPersonIndex(Participant participant)
        {
            DoubleList <Book> bookDoubleList = new DoubleList <Book>();

            participant.WishList.ForEach(b => bookDoubleList.AddToWish(b));
            participant.GiveList.ForEach(b => bookDoubleList.AddToGive(b));
            personIndex.Add(participant.Person, bookDoubleList);
        }
Beispiel #17
0
        public void DoubleListClearAllTestMethod()
        {
            DoubleList <Worker> list = new DoubleList <Worker>();

            list.Add(new Worker("da", "net", 12, "fire"));
            list.Clear();
            Assert.AreEqual(0, list.Count);
        }
Beispiel #18
0
 private void CollectValue(ValueEval ve, bool isViaReference, DoubleList temp)
 {
     if (ve == null)
     {
         throw new ArgumentException("ve must not be null");
     }
     if (ve is BoolEval)
     {
         if (!isViaReference || _isReferenceBoolCounted)
         {
             BoolEval boolEval = (BoolEval)ve;
             temp.Add(boolEval.NumberValue);
         }
         return;
     }
     if (ve is NumberEval)
     {
         NumberEval ne = (NumberEval)ve;
         temp.Add(ne.NumberValue);
         return;
     }
     if (ve is StringEval)
     {
         if (isViaReference)
         {
             // ignore all ref strings
             return;
         }
         String s = ((StringEval)ve).StringValue;
         Double d = OperandResolver.ParseDouble(s);
         if (double.IsNaN(d))
         {
             throw new EvaluationException(ErrorEval.VALUE_INVALID);
         }
         temp.Add(d);
         return;
     }
     if (ve is ErrorEval)
     {
         throw new EvaluationException((ErrorEval)ve);
     }
     if (ve == BlankEval.instance)
     {
         if (_isBlankCounted)
         {
             temp.Add(0.0);
         }
         return;
     }
     if (ve is NumberValueArrayEval nvae)
     {
         temp.Add(nvae.NumberValues);
         return;
     }
     throw new InvalidOperationException("Invalid ValueEval type passed for conversion: ("
                                         + ve.GetType() + ")");
 }
Beispiel #19
0
 private static void DisplayList(DoubleList <int> linkedList, bool reverse)
 {
     if (!reverse)
     {
         linkedList.Display();
         return;
     }
     linkedList.DisplayReverse();
 }
Beispiel #20
0
 public JobManagerState()
 {
     this.batchSizeList     = new IntegerList();
     this.dueDateList       = new DoubleList();
     this.jobMix            = new JobMixState();
     this.jobs              = new JobStateList();
     this.unitloads         = new UnitloadStateList();
     this.unitloadsToDecide = new StringList();
     this.unitloadsToRoute  = new StringList();
 }
Beispiel #21
0
        public void testLength()
        {
            DoubleList <int> tester = new DoubleList <int>();

            Assert.AreEqual(tester.Length(), 0);
            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            Assert.AreEqual(tester.Length(), 3);
        }
Beispiel #22
0
        public void DoubleList_Clear()
        {
            var list = new DoubleList();

            list.AddToFront(new V(2));
            list.AddToFront(new V(1));
            list.AddToFront(new V(0));
            list.Clear();
            Assert.AreEqual(0, list.Count);
        }
        public WorldStateManager()
        {
            _allActings = new DoubleList <Acting> [World.NumOrders];

            for (int i = 0; i < _allActings.Length; i++)
            {
                _allActings[i] = new DoubleList <Acting>();
            }

            _allTickings = new DoubleList <Ticking>();
        }
Beispiel #24
0
        public void DoubleList_IndexWithAdd()
        {
            var list = new DoubleList();

            list.AddToEnd(new V(0));
            Assert.AreEqual(0, ((V)list[0]).Value);
            list.AddToEnd(new V(1));
            list.AddToEnd(new V(2));
            Assert.AreEqual(0, ((V)list[0]).Value);
            Assert.AreEqual(2, ((V)list[2]).Value);
        }
Beispiel #25
0
        public void testAppendFirst()
        {
            DoubleList <int> tester = new DoubleList <int>();

            Assert.Null(tester.GetHead());
            tester.Append(0);
            Assert.NotNull(tester.GetHead());
            Object appended = tester.GetHead().GetValue();

            Assert.AreEqual(appended, 0);
        }
Beispiel #26
0
        public void TestmetodAdd()
        {
            DoubleList list = new DoubleList();
            string     str  = "123";

            list.AddWord(str);
            list.AddWord("321");
            list.AddWord("325");
            list.AddWord("321");
            str = "555";
        }
Beispiel #27
0
        public void testDeleteLast()
        {
            DoubleList <int> tester = new DoubleList <int>();

            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            tester.Delete(2);
            Assert.Null(tester.GetHead().GetNext().GetNext());
            Assert.AreEqual(tester.Length(), 2);
        }
Beispiel #28
0
        public DoubleList GetRange(int index, int count)
        {
            global::System.IntPtr cPtr = LandmarkDetectorPINVOKE.DoubleList_GetRange(swigCPtr, index, count);
            DoubleList            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new DoubleList(cPtr, true);

            if (LandmarkDetectorPINVOKE.SWIGPendingException.Pending)
            {
                throw LandmarkDetectorPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #29
0
        public static DoubleList Repeat(double value, int count)
        {
            global::System.IntPtr cPtr = LandmarkDetectorPINVOKE.DoubleList_Repeat(value, count);
            DoubleList            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new DoubleList(cPtr, true);

            if (LandmarkDetectorPINVOKE.SWIGPendingException.Pending)
            {
                throw LandmarkDetectorPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #30
0
        public void SecondayListAdd_ShouldAddItem(
          DoubleList<object> sut,
            object expected)
        {
            //arrange

            //act
            sut.SecondaryList.Add(expected);

            //assert
            sut.Should().Contain(expected);
        }
Beispiel #31
0
        public void testAppend()
        {
            DoubleList <int> tester = new DoubleList <int>();

            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            Object appended = tester.GetHead().GetNext().GetNext().GetValue();

            Assert.AreEqual(appended, 2);
            Assert.AreEqual(tester.GetHead().GetNext().GetPrevious(), tester.GetHead());
        }
Beispiel #32
0
        public void Remove_ShouldRemoveItem(
          DoubleList<object> sut,
            object expected)
        {
            //arrange
            sut.Add(expected);

            //act
            sut.Remove(expected);

            //assert
            sut.Should().NotContain(expected);
        }
Beispiel #33
0
        public void Remove_WhenItemIsInSecondaryList_ShouldRemoveItem(
          DoubleList<object> sut,
            object expected)
        {
            //arrange
            sut.SecondaryList.Add(expected);

            //act
            sut.Remove(expected);

            //assert
            sut.Should().NotContain(expected);
            sut.SecondaryList.Should().NotContain(expected);
        }
Beispiel #34
0
        public void GetEnumerator_ShouldReturnAllItemsInOrder(
          DoubleList<object> sut,
            object item,
            object secondaryItem)
        {
            //arrange
            sut.SecondaryList.Add(secondaryItem);
            sut.Add(item);

            //act
            var actual = new List<object>();
            foreach (var i in sut)
            {
                actual.Add(i);
            }

            //assert
            var expected = new List<object>() { item, secondaryItem };
            actual.ShouldAllBeEquivalentTo(expected);
        }
        /**
         * Returns a double array that contains values for the numeric cells
         * from among the list of operands. Blanks and Blank equivalent cells
         * are ignored. Error operands or cells containing operands of type
         * that are considered invalid and would result in #VALUE! error in
         * excel cause this function to return <c>null</c>.
         *
         * @return never <c>null</c>
         */
        protected double[] GetNumberArray(ValueEval[] operands)
        {
            if (operands.Length > MaxNumOperands)
            {
                throw EvaluationException.InvalidValue();
            }
            DoubleList retval = new DoubleList();

            for (int i = 0, iSize = operands.Length; i < iSize; i++)
            {
                CollectValues(operands[i], retval);
            }
            return retval.ToArray();
        }
 private void CollectValue(ValueEval ve, bool isViaReference, DoubleList temp)
 {
     if (ve == null)
     {
         throw new ArgumentException("ve must not be null");
     }
     if (ve is NumberEval)
     {
         NumberEval ne = (NumberEval)ve;
         temp.Add(ne.NumberValue);
         return;
     }
     if (ve is ErrorEval)
     {
         throw new EvaluationException((ErrorEval)ve);
     }
     if (ve is StringEval)
     {
         if (isViaReference)
         {
             // ignore all ref strings
             return;
         }
         String s = ((StringEval)ve).StringValue;
         Double d = OperandResolver.ParseDouble(s);
         if (double.IsNaN(d))
         {
             throw new EvaluationException(ErrorEval.VALUE_INVALID);
         }
         temp.Add(d);
         return;
     }
     if (ve is BoolEval)
     {
         if (!isViaReference || _isReferenceBoolCounted)
         {
             BoolEval boolEval = (BoolEval)ve;
             temp.Add(boolEval.NumberValue);
         }
         return;
     }
     if (ve == BlankEval.instance)
     {
         if (_isBlankCounted)
         {
             temp.Add(0.0);
         }
         return;
     }
     throw new InvalidOperationException("Invalid ValueEval type passed for conversion: ("
             + ve.GetType() + ")");
 }
        /**
 * Collects values from a single argument
 */
        private void CollectValues(ValueEval operand, DoubleList temp)
        {

            if (operand is TwoDEval)
            {
                TwoDEval ae = (TwoDEval)operand;
                int width = ae.Width;
                int height = ae.Height;
                for (int rrIx = 0; rrIx < height; rrIx++)
                {
                    for (int rcIx = 0; rcIx < width; rcIx++)
                    {
                        ValueEval ve = ae.GetValue(rrIx, rcIx);
                        if (!IsSubtotalCounted && ae.IsSubTotal(rrIx, rcIx)) continue;
                        CollectValue(ve, true, temp);
                    }
                }
                return;
            }
            if (operand is RefEval)
            {
                RefEval re = (RefEval)operand;
                CollectValue(re.InnerValueEval, true, temp);
                return;
            }
            CollectValue((ValueEval)operand, false, temp);
        }
Beispiel #38
0
        public void Insert_ShouldInsertItem(
            int factor,
            object item,
          DoubleList<object> sut,
            object[] items,
            object[] secondaryItems)
        {
            //arrange
            sut.AddRange(items);
            sut.SecondaryList.AddRange(secondaryItems);
            var index = items.Length - 1 + factor;
            //act

            sut.Insert(index, item);

            //assert
            sut.Should().HaveElementAt(index, item);
        }
        	/**
	 * Collects values from a single argument
	 */
	private void CollectValues(Eval operand, DoubleList temp){

		if (operand is AreaEval) {
			AreaEval ae = (AreaEval) operand;
			int width = ae.Width;
			int height = ae.Height;
			for (int rrIx=0; rrIx<height; rrIx++) {
				for (int rcIx=0; rcIx<width; rcIx++) {
					ValueEval ve = ae.GetRelativeValue(rrIx, rcIx);
					CollectValue(ve, true, temp);
				}
			}
			return;
		}
		if (operand is RefEval) {
			RefEval re = (RefEval) operand;
			CollectValue(re.InnerValueEval, true, temp);
			return;
		}
		CollectValue((ValueEval)operand, false, temp);
	}
Beispiel #40
0
        public static void ProcessLog(string fn)
        {
            using (CollectionBuffer colbuf = new CollectionBuffer(File.OpenRead(fn)))
            {

                // store all the arrays
                List<MLArray> mlList = new List<MLArray>();
                // store data to putinto the arrays
                Dictionary<string, DoubleList> data = new Dictionary<string, DoubleList>();
                // store line item lengths
                Hashtable len = new Hashtable();
                // store whats we have seen in the log
                Hashtable seen = new Hashtable();
                // store the params seen
                SortedDictionary<string, double> param = new SortedDictionary<string, double>();

                // keep track of line no
                int a = 0;

                log.Info("ProcessLog start " + (GC.GetTotalMemory(false)/1024.0/1024.0));

                foreach (var line in colbuf)
                {
                    a++;
                    if (a%100 == 0)
                        Console.Write(a + "\r");

                    string strLine = line.Replace(", ", ",");
                    strLine = strLine.Replace(": ", ":");

                    string[] items = strLine.Split(',', ':');

                    // process the fmt messages
                    if (line.StartsWith("FMT"))
                    {
                        // +1 for line no
                        string[] names = new string[items.Length - 5 + 1];
                        names[0] = "LineNo";
                        Array.ConstrainedCopy(items, 5, names, 1, names.Length - 1);

                        MLArray format = CreateCellArray(items[3] + "_label", names);

                        if (items[3] == "PARM")
                        {
                        }
                        else
                        {
                            mlList.Add(format);
                        }

                        len[items[3]] = names.Length;
                    } // process param messages
                    else if (line.StartsWith("PARM"))
                    {
                        try
                        {
                            param[items[2]] = double.Parse(items[3], CultureInfo.InvariantCulture);
                        }
                        catch
                        {
                        }
                    } // everyting else is generic
                    else
                    {
                        // make sure the line is long enough
                        if (items.Length < 2)
                            continue;
                        // check we have a valid fmt message for this message type
                        if (!len.ContainsKey(items[0]))
                            continue;
                        // check the fmt length matchs what the log has
                        if (items.Length != (int) len[items[0]])
                            continue;

                        // make it as being seen
                        seen[items[0]] = 1;

                        double[] dbarray = new double[items.Length];

                        // set line no
                        dbarray[0] = a;

                        for (int n = 1; n < items.Length; n++)
                        {
                            double dbl = 0;

                            double.TryParse(items[n], NumberStyles.Any, CultureInfo.InvariantCulture, out dbl);

                            dbarray[n] = dbl;
                        }

                        if (!data.ContainsKey(items[0]))
                            data[items[0]] = new DoubleList();

                        data[items[0]].Add(dbarray);
                    }

                    // split at x records
                    if (a%2000000 == 0 && !Environment.Is64BitProcess)
                    {
                        GC.Collect();
                        DoWrite(fn + "-" + a, data, param, mlList, seen);
                        mlList.Clear();
                        data.Clear();
                        param.Clear();
                        seen.Clear();
                        GC.Collect();
                    }
                }

                DoWrite(fn + "-" + a, data, param, mlList, seen);
            }
        }
Beispiel #41
0
        public static void ProcessLog(string fn)
        {
            StreamReader sr;

            if (fn.ToLower().EndsWith(".bin"))
            {
                string tmpfile = Path.GetTempFileName();
                BinaryLog.ConvertBin(fn, tmpfile);
                sr = new StreamReader(tmpfile);
            }
            else
            {
                sr = new StreamReader(fn);
            }

            // store all the arrays
            List<MLArray> mlList = new List<MLArray>();
            // store data to putinto the arrays
            Dictionary<string, DoubleList> data = new Dictionary<string, DoubleList>();
            // store line item lengths
            Hashtable len = new Hashtable();
            // store whats we have seen in the log
            Hashtable seen = new Hashtable();
            // store the params seen
            SortedDictionary<string, double> param = new SortedDictionary<string, double>();

            // keep track of line no
            int a = 0;

            log.Info("ProcessLog start " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();

                a++;
                if (a % 100 == 0)
                    Console.Write(a + "\r");

                string strLine = line.Replace(", ", ",");
                strLine = strLine.Replace(": ", ":");

                string[] items = strLine.Split(',', ':');

                // process the fmt messages
                if (line.StartsWith("FMT"))
                {
                    // +1 for line no
                    string[] names = new string[items.Length - 5 + 1];
                    names[0] = "LineNo";
                    Array.ConstrainedCopy(items, 5, names, 1, names.Length - 1);

                    MLArray format = CreateCellArray(items[3] + "_label", names);

                    if (items[3] == "PARM")
                    {

                    }
                    else
                    {
                        mlList.Add(format);
                    }

                    len[items[3]] = names.Length;
                } // process param messages
                else if (line.StartsWith("PARM"))
                {
                    try
                    {
                        param[items[1]] = double.Parse(items[2], CultureInfo.InvariantCulture);
                    }
                    catch { }
                }// everyting else is generic
                else
                {
                    // make sure the line is long enough
                    if (items.Length < 2)
                        continue;
                    // check we have a valid fmt message for this message type
                    if (!len.ContainsKey(items[0]))
                        continue;
                    // check the fmt length matchs what the log has
                    if (items.Length != (int)len[items[0]])
                        continue;

                    // make it as being seen
                    seen[items[0]] = 1;

                    double[] dbarray = new double[items.Length];

                    // set line no
                    dbarray[0] = a;

                    for (int n = 1; n < items.Length; n++)
                    {
                        try
                        {
                            dbarray[n] = double.Parse(items[n], CultureInfo.InvariantCulture);
                        }
                        catch { }
                    }

                    if (!data.ContainsKey(items[0]))
                        data[items[0]] = new DoubleList();

                    data[items[0]].Add(dbarray);
                }

                // split at x records
                if (a % 2000000 == 0)
                {
                    GC.Collect();
                    DoWrite(fn + "-" + a, data, param, mlList, seen);
                    mlList.Clear();
                    data.Clear();
                    param.Clear();
                    seen.Clear();
                    GC.Collect();
                }
            }

            DoWrite(fn + "-" + a, data, param, mlList, seen);

            sr.Close();
        }