MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
TemporalDescriptor.cs
1using System;
2using System.Collections.Generic;
3using System.Collections.ObjectModel;
5using System.IO;
6using System.Linq;
7using System.Runtime.InteropServices.WindowsRuntime;
8using System.Security.Policy;
9using System.Text;
10using System.Threading.Tasks;
12
14{
18 [Serializable]
19 [TypeConverter(typeof(ExpandableObjectConverter))]
20 public class TemporalDescriptor
21 {
22 List<ValueStreamDescriptor> m_rgValStrmDesc = new List<ValueStreamDescriptor>();
23 List<ValueItemDescriptor> m_rgValItemDesc = new List<ValueItemDescriptor>();
24
29 {
30 }
31
37 {
38 foreach (ValueStreamDescriptor vsd in td.m_rgValStrmDesc)
39 {
40 m_rgValStrmDesc.Add(new ValueStreamDescriptor(vsd));
41 }
42
43 foreach (ValueItemDescriptor vid in td.m_rgValItemDesc)
44 {
45 m_rgValItemDesc.Add(new ValueItemDescriptor(vid));
46 }
47 }
48
52 [ReadOnly(true)]
53 public List<ValueStreamDescriptor> ValueStreamDescriptors
54 {
55 get { return m_rgValStrmDesc; }
56 set { m_rgValStrmDesc = value; }
57 }
58
62 [Browsable(false)]
64 {
65 get { return new OrderedValueStreamDescriptorSet(m_rgValStrmDesc); }
66 }
67
71 [Browsable(false)]
72 public List<ValueItemDescriptor> ValueItemDescriptors
73 {
74 get { return m_rgValItemDesc; }
75 set { m_rgValItemDesc = value; }
76 }
77
81 public ReadOnlyCollection<ValueItemDescriptor> ValueItemDescriptorItems
82 {
83 get { return m_rgValItemDesc.AsReadOnly(); }
84 }
85
89 public int TotalSteps
90 {
91 get
92 {
93 int nTotal = 0;
94
95 foreach (ValueStreamDescriptor vsd in m_rgValStrmDesc)
96 {
97 nTotal = Math.Max(nTotal, vsd.Steps);
98 }
99
100 return nTotal;
101 }
102 }
103
107 public DateTime? StartDate
108 {
109 get
110 {
111 DateTime dt = m_rgValStrmDesc.Min(p => p.Start.GetValueOrDefault(DateTime.MaxValue));
112 if (dt == DateTime.MaxValue)
113 return null;
114
115 return dt;
116 }
117 }
118
122 public DateTime? EndDate
123 {
124 get
125 {
126 DateTime dt = m_rgValStrmDesc.Max(p => p.End.GetValueOrDefault(DateTime.MinValue));
127 if (dt == DateTime.MinValue)
128 return null;
129
130 return dt;
131 }
132 }
133
139 public static TemporalDescriptor FromBytes(byte[] rgb)
140 {
141 if (rgb == null)
142 return null;
143
145
146 using (MemoryStream ms = new MemoryStream(rgb))
147 using (BinaryReader br = new BinaryReader(ms))
148 {
149 int nCount = br.ReadInt32();
150 for (int i = 0; i < nCount; i++)
151 {
152 desc.m_rgValStrmDesc.Add(ValueStreamDescriptor.FromBytes(br));
153 }
154
155 nCount = br.ReadInt32();
156 for (int i = 0; i < nCount; i++)
157 {
158 desc.m_rgValItemDesc.Add(ValueItemDescriptor.FromBytes(br));
159 }
160 }
161
162 return desc;
163 }
164
169 public byte[] ToBytes()
170 {
171 using (MemoryStream ms = new MemoryStream())
172 using (BinaryWriter bw = new BinaryWriter(ms))
173 {
174 bw.Write(m_rgValStrmDesc.Count);
175 foreach (ValueStreamDescriptor vid in m_rgValStrmDesc)
176 {
177 vid.ToBytes(bw);
178 }
179
180 bw.Write(m_rgValItemDesc.Count);
181 foreach (ValueItemDescriptor vid in m_rgValItemDesc)
182 {
183 vid.ToBytes(bw);
184 }
185
186 return ms.ToArray();
187 }
188 }
189 }
190
195 {
196 Dictionary<STREAM_CLASS_TYPE, Dictionary<STREAM_VALUE_TYPE, List<ValueStreamDescriptor>>> m_rgOrdered = new Dictionary<STREAM_CLASS_TYPE, Dictionary<STREAM_VALUE_TYPE, List<ValueStreamDescriptor>>>();
197
202 public OrderedValueStreamDescriptorSet(List<ValueStreamDescriptor> rg)
203 {
204 foreach (ValueStreamDescriptor vsd in rg)
205 {
206 if (!m_rgOrdered.ContainsKey(vsd.ClassType))
207 m_rgOrdered.Add(vsd.ClassType, new Dictionary<STREAM_VALUE_TYPE, List<ValueStreamDescriptor>>());
208
209 if (!m_rgOrdered[vsd.ClassType].ContainsKey(vsd.ValueType))
210 m_rgOrdered[vsd.ClassType].Add(vsd.ValueType, new List<ValueStreamDescriptor>());
211
212 m_rgOrdered[vsd.ClassType][vsd.ValueType].Add(vsd);
213 }
214 }
215
222 public List<ValueStreamDescriptor> GetStreamDescriptors(STREAM_CLASS_TYPE classType, STREAM_VALUE_TYPE valueType)
223 {
224 if (!m_rgOrdered.ContainsKey(classType))
225 return null;
226
227 if (!m_rgOrdered[classType].ContainsKey(valueType))
228 return null;
229
230 return m_rgOrdered[classType][valueType];
231 }
232 }
233
237 [Serializable]
238 [TypeConverter(typeof(ExpandableObjectConverter))]
240 {
241 int m_nID;
242 string m_strName;
243 DateTime? m_dtStart;
244 DateTime? m_dtEnd;
245 int? m_nSteps;
246
255 public ValueItemDescriptor(int nID, string strName, DateTime? dtStart, DateTime? dtEnd, int? nSteps)
256 {
257 m_nID = nID;
258 m_strName = strName;
259 m_dtStart = dtStart;
260 m_dtEnd = dtEnd;
261 m_nSteps = nSteps;
262 }
263
269 {
270 m_nID = vid.m_nID;
271 m_strName = vid.m_strName;
272 m_dtStart = vid.m_dtStart;
273 m_dtEnd = vid.m_dtEnd;
274 m_nSteps = vid.m_nSteps;
275 }
276
282 public static ValueItemDescriptor FromBytes(BinaryReader br)
283 {
284 int nID = br.ReadInt32();
285 string strName = br.ReadString();
286 DateTime? dtStart = null;
287 DateTime? dtEnd = null;
288 int? nSteps = null;
289
290 if (br.ReadBoolean())
291 {
292 dtStart = new DateTime(br.ReadInt64());
293 dtEnd = new DateTime(br.ReadInt64());
294 nSteps = br.ReadInt32();
295 }
296
297 ValueItemDescriptor desc = new ValueItemDescriptor(nID, strName, dtStart, dtEnd, nSteps);
298 return desc;
299 }
300
306 public void ToBytes(BinaryWriter bw)
307 {
308 bw.Write(m_nID);
309 bw.Write(m_strName);
310
311 if (m_dtStart.HasValue && m_dtEnd.HasValue && m_nSteps.HasValue)
312 {
313 bw.Write(true);
314 bw.Write(m_dtStart.Value.Ticks);
315 bw.Write(m_dtEnd.Value.Ticks);
316 bw.Write(m_nSteps.Value);
317 }
318 else
319 {
320 bw.Write(false);
321 }
322 }
323
327 [ReadOnly(true)]
328 public int ID
329 {
330 get { return m_nID; }
331 }
332
336 [ReadOnly(true)]
337 public string Name
338 {
339 get { return m_strName; }
340 }
341
345 [ReadOnly(true)]
346 public DateTime? Start
347 {
348 get { return m_dtStart; }
349 }
350
354 [ReadOnly(true)]
355 public DateTime? End
356 {
357 get { return m_dtEnd; }
358 }
359
363 [ReadOnly(true)]
364 public int? Steps
365 {
366 get { return m_nSteps; }
367 }
368
373 public override string ToString()
374 {
375 return m_strName;
376 }
377 }
378
382 [Serializable]
383 [TypeConverter(typeof(ExpandableObjectConverter))]
385 {
386 STREAM_CLASS_TYPE m_classType = STREAM_CLASS_TYPE.STATIC;
387 STREAM_VALUE_TYPE m_valueType = STREAM_VALUE_TYPE.NUMERIC;
388 int m_nID;
389 string m_strName;
390 int m_nOrdering;
391 DateTime? m_dtStart = null;
392 DateTime? m_dtEnd = null;
393 int? m_nSecondsPerStep = null;
394 int m_nSteps = 0;
395
400 {
404 NUMERIC = 0x01,
408 CATEGORICAL = 0x02
409 }
410
415 {
419 STATIC = 0x01,
423 OBSERVED = 0x02,
427 KNOWN = 0x04
428 }
429
442 public ValueStreamDescriptor(int nID, string strName, int nOrdering, STREAM_CLASS_TYPE classType, STREAM_VALUE_TYPE valueType, DateTime? dtStart = null, DateTime? dtEnd = null, int? nSecPerStep = null, int nSteps = 1)
443 {
444 m_nID = nID;
445 m_strName = strName;
446 m_nOrdering = nOrdering;
447 m_classType = classType;
448 m_valueType = valueType;
449 m_dtStart = dtStart;
450 m_dtEnd = dtEnd;
451 m_nSecondsPerStep = nSecPerStep;
452 m_nSteps = nSteps;
453 }
454
460 {
461 m_nID = vsd.m_nID;
462 m_strName = vsd.m_strName;
463 m_nOrdering = vsd.m_nOrdering;
464 m_classType = vsd.m_classType;
465 m_valueType = vsd.m_valueType;
466 m_dtStart = vsd.m_dtStart;
467 m_dtEnd = vsd.m_dtEnd;
468 m_nSecondsPerStep = vsd.m_nSecondsPerStep;
469 m_nSteps = vsd.m_nSteps;
470 }
471
477 public static ValueStreamDescriptor FromBytes(BinaryReader br)
478 {
479 int nID = br.ReadInt32();
480 string strName = br.ReadString();
481 int nOrdering = br.ReadInt32();
482 STREAM_CLASS_TYPE classType = (STREAM_CLASS_TYPE)br.ReadInt32();
483 STREAM_VALUE_TYPE valueType = (STREAM_VALUE_TYPE)br.ReadInt32();
484 DateTime? dtStart = null;
485 DateTime? dtEnd = null;
486 int? nSecondsPerStep = null;
487
488 bool bHasStart = br.ReadBoolean();
489 if (bHasStart)
490 dtStart = new DateTime(br.ReadInt64());
491
492 bool bHasEnd = br.ReadBoolean();
493 if (bHasEnd)
494 dtEnd = new DateTime(br.ReadInt64());
495
496 bool bHasSecondsPerStep = br.ReadBoolean();
497 if (bHasSecondsPerStep)
498 nSecondsPerStep = br.ReadInt32();
499
500 int nSteps = br.ReadInt32();
501
502 return new ValueStreamDescriptor(nID, strName, nOrdering, classType, valueType, dtStart, dtEnd, nSecondsPerStep, nSteps);
503 }
504
509 public void ToBytes(BinaryWriter bw)
510 {
511 bw.Write(m_nID);
512 bw.Write(m_strName);
513 bw.Write(m_nOrdering);
514 bw.Write((int)m_classType);
515 bw.Write((int)m_valueType);
516
517 bw.Write(m_dtStart.HasValue);
518 if (m_dtStart.HasValue)
519 bw.Write(m_dtStart.Value.Ticks);
520
521 bw.Write(m_dtEnd.HasValue);
522 if (m_dtEnd.HasValue)
523 bw.Write(m_dtEnd.Value.Ticks);
524
525 bw.Write(m_nSecondsPerStep.HasValue);
526 if (m_nSecondsPerStep.HasValue)
527 bw.Write(m_nSecondsPerStep.Value);
528
529 bw.Write(m_nSteps);
530 }
531
535 [ReadOnly(true)]
536 public int ID
537 {
538 get { return m_nID; }
539 }
540
544 [ReadOnly(true)]
545 public string Name
546 {
547 get { return m_strName; }
548 }
549
553 [ReadOnly(true)]
554 public int Ordering
555 {
556 get { return m_nOrdering; }
557 }
558
562 [ReadOnly(true)]
564 {
565 get { return m_classType; }
566 }
567
571 [ReadOnly(true)]
573 {
574 get { return m_valueType; }
575 }
576
580 [ReadOnly(true)]
581 public DateTime? Start
582 {
583 get { return m_dtStart; }
584 }
585
589 [ReadOnly(true)]
590 public DateTime? End
591 {
592 get { return m_dtEnd; }
593 }
594
598 [ReadOnly(true)]
599 public int? SecondsPerStep
600 {
601 get { return m_nSecondsPerStep; }
602 }
603
607 [ReadOnly(true)]
608 public int Steps
609 {
610 get { return m_nSteps; }
611 }
612
617 public override string ToString()
618 {
619 string strOut = m_nOrdering.ToString() + ". " + m_strName + " (" + m_classType.ToString() + ", " + m_valueType.ToString() + ")";
620
621 if (m_dtStart.HasValue)
622 strOut += " start = " + m_dtStart.ToString();
623
624 if (m_dtEnd.HasValue)
625 strOut += " end = " + m_dtEnd.ToString();
626
627 if (m_nSecondsPerStep.HasValue)
628 strOut += " seconds_per_step = " + m_nSecondsPerStep.ToString();
629
630 return strOut;
631 }
632 }
633}
The ordered value stream descriptor set is used to order the value stream descriptors by class and va...
OrderedValueStreamDescriptorSet(List< ValueStreamDescriptor > rg)
The constructor.
List< ValueStreamDescriptor > GetStreamDescriptors(STREAM_CLASS_TYPE classType, STREAM_VALUE_TYPE valueType)
Retrieves the set of stream descriptors with the given class and value type.
The TemporalDescriptor is used to describe a temporal aspects of the data source.
OrderedValueStreamDescriptorSet OrderedValueStreamDescriptors
Retunrs the ordered set of stream descriptors.
byte[] ToBytes()
Returns the temporal descriptor as a byte array.
int TotalSteps
Returns the total number of temporal steps.
ReadOnlyCollection< ValueItemDescriptor > ValueItemDescriptorItems
Returns the value item descriptors as a read-only array.
static TemporalDescriptor FromBytes(byte[] rgb)
Returns a new TemporalDescriptor from a byte array.
List< ValueItemDescriptor > ValueItemDescriptors
Returns the value item descriptor.
TemporalDescriptor(TemporalDescriptor td)
The constructor.
List< ValueStreamDescriptor > ValueStreamDescriptors
Returns the value stream descriptor.
The ValueItemDescriptor describes each value item (e.g., customer, station or stock)
void ToBytes(BinaryWriter bw)
Returns the value item descriptor as a byte array.
ValueItemDescriptor(ValueItemDescriptor vid)
The copy constructor.
DateTime? Start
Returns the start time (if any).
ValueItemDescriptor(int nID, string strName, DateTime? dtStart, DateTime? dtEnd, int? nSteps)
The constructor.
DateTime? End
Returns the end time (if any).
static ValueItemDescriptor FromBytes(BinaryReader br)
Returns a new ValueItemDescriptor from a binary reader.
override string ToString()
Returns a string representation of the value item descriptor.
The value stream descriptor describes a single value stream within a value item.
STREAM_CLASS_TYPE ClassType
Returns the value stream class type.
int? SecondsPerStep
Returns the value stream seconds per step (null with STATIC class).
void ToBytes(BinaryWriter bw)
Returns the value stream descriptor as a byte array.
override string ToString()
Returns the string rendering of the value stream descriptor.
int Ordering
Returns the value stream ordering.
int Steps
Returns the number of items in the value stream.
DateTime? End
Returns the value stream end time (null with STATIC class).
static ValueStreamDescriptor FromBytes(BinaryReader br)
Returns a new ValueStreamDescriptor from a byte array.
STREAM_VALUE_TYPE ValueType
Returns the value stream value type.
ValueStreamDescriptor(int nID, string strName, int nOrdering, STREAM_CLASS_TYPE classType, STREAM_VALUE_TYPE valueType, DateTime? dtStart=null, DateTime? dtEnd=null, int? nSecPerStep=null, int nSteps=1)
The constructor.
ValueStreamDescriptor(ValueStreamDescriptor vsd)
The constructor.
DateTime? Start
Returns the value stream start time (null with STATIC class).
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12