/// <summary> /// Analyzes a sequence of events. Optionally writes data file pair /// </summary> /// <param name="times">The event times in clock ticks.</param> /// <param name="channelMasks">The event channel masks.</param> /// <param name="count">The number of events.</param> private void Analyze(List <ulong> times, List <uint> channelMasks, int count) { for (int i = 0; i < count; i++) { for (int channel = 0; channel < Ptr32.ChannelCount; channel++) { if ((channelMasks[i] & (1u << channel)) != 0) { cycle.HitsPerChannel[channel]++; cycle.Totals++; } } } cycle.TotalEvents += (ulong)count; cycle.TS = TimeSpan.FromTicks((long)times[count - 1] / (Ptr32.Frequency / TimeSpan.TicksPerSecond)); if (cycle.Totals > 0 && cycle.TS.TotalSeconds > 0.0) { cycle.SinglesRate = cycle.Totals / cycle.TS.TotalSeconds; } Sup.HandleAnArrayOfNeutronEvents(times, channelMasks, count); if (m_writingFile) { file.Channels.Write(channelMasks, 0, count); file.Events.Write(times, 0, count); } }
static void Main(string[] args) { var sup = new Sup(); var lates = new Lates(); var mapping = new Dictionary <String, Word>(StringComparer.OrdinalIgnoreCase) { { "hi", sup }, { "hello", sup }, { "hey", sup }, { "bye", lates }, { "later", lates }, { "astalavista", lates }, }; Word word; if (mapping.TryGetValue("HELLO", out word)) { Console.WriteLine(word.GetResponse()); } if (mapping.TryGetValue("astalavista", out word)) { Console.WriteLine(word.GetResponse()); } if (mapping.TryGetValue("blaglarg", out word)) { Console.WriteLine(word.GetResponse()); } }
public IHttpActionResult PutSup(int id, Sup sup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != sup.SupId) { return(BadRequest()); } db.Entry(sup).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetSup(int id) { Sup sup = db.Sups.Find(id); if (sup == null) { return(NotFound()); } return(Ok(sup)); }
public IHttpActionResult PostSup(Sup sup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Sups.Add(sup); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = sup.SupId }, sup)); }
public override void DoWork(Serial thisSensor) { PMSensordata thisReading = new PMSensordata { Pm1_atm = (DateTime.Now - DateTime.UnixEpoch).TotalSeconds % 86400 / 86400 * 50, Pm25_atm = (DateTime.Now - DateTime.UnixEpoch).TotalSeconds % 86400 / 86400 * 100, Pm10_atm = (DateTime.Now - DateTime.UnixEpoch).TotalSeconds % 86400 / 86400 * 200 }; Sup.LogTraceInfoMessage($"Serial data read: {thisReading.Pm1_atm:F1}; {thisReading.Pm25_atm:F1}; {thisReading.Pm10_atm:F1};"); thisSensor.ObservationList.Add(thisReading); }
public async Task <ActionResult> Create([Bind(Include = "Name,SupId")] Sup Sup, HttpPostedFileBase file) { db.Sups.Add(Sup); await db.SaveChangesAsync(); TempData["Success"] = true; return(RedirectToAction("Details", new { id = Sup.SupId })); ViewBag.SupId = new SelectList(db.Sups, "SupId", "Name", Sup.SupId); ViewBag.uploadInfo = "Đường dẫn hình ảnh: !"; return(View(Sup)); }
// GET: StoreManager/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sup Tea = await db.Sups.FindAsync(id); if (Tea == null) { return(HttpNotFound()); } return(View(Tea)); }
public override void Close() { try { thisSerial.Close(); Sup.LogDebugMessage($"Serial: Closed the port on {SensorUsed}"); } catch (IOException e) { Sup.LogTraceErrorMessage($"Serial: Exception on Close {SensorUsed}: {e.Message}"); } Valid = false; }
public IHttpActionResult DeleteSup(int id) { Sup sup = db.Sups.Find(id); if (sup == null) { return(NotFound()); } db.Sups.Remove(sup); db.SaveChanges(); return(Ok(sup)); }
public override void DoWork(Serial thisSensor) { PMSensordata thisReading = new PMSensordata(); // Read the input buffer, throw away all other data in the buffer and read again // Do this as long as there is no 32 characters in the buffer (the minimum) // As it fills appr every second the 5 second read I implement should be enough try { int Count; if (thisSerial.BytesToRead > 0) { do { lock ( buffer ) { Count = thisSerial.Read(buffer, 0, 32); thisSerial.DiscardInBuffer(); } // Below is for debugging, takes performance Sup.LogTraceInfoMessage($"Trying {Count} chars: {buffer[ 0 ]:x2}/{buffer[ 1 ]:x2}"); } while (Count < 32 || (buffer[0] != 0x42 || buffer[1] != 0x4d)); // Below is for debugging, takes performance // string _hex = Sup.ByteArrayToHexString(buffer); Sup.LogTraceInfoMessage($"Nr of Bytes {Count}: {Sup.ByteArrayToHexString( buffer )}"); thisReading.Pm1_atm = buffer[10] * 255 + buffer[11]; thisReading.Pm25_atm = buffer[12] * 255 + buffer[13]; thisReading.Pm10_atm = buffer[14] * 255 + buffer[15]; Sup.LogTraceInfoMessage($"Serial data read: {thisReading.Pm1_atm:F1}; {thisReading.Pm25_atm:F1}; {thisReading.Pm10_atm:F1};"); thisSensor.ObservationList.Add(thisReading); } } catch (Exception e) when(e is ArgumentOutOfRangeException || e is ArgumentException || e is TimeoutException || e is InvalidOperationException || e is ArgumentNullException || e is IOException) { Sup.LogTraceWarningMessage($"DoPMS1003: Exception on Serial Read => {e.Message}"); // Continue reading } }
}// PMS1003 Constructor public override void Open() { thisSerial = new SerialPort(Port.SerialPortUsed, Port.SerialBaudRate, Port.SerialParity, Port.SerialDataBits, Port.SerialNrOfStopBits) { ReadTimeout = 500 }; try { thisSerial.Open(); Sup.LogDebugMessage($"Serial: Opened the port {Port.SerialPortUsed}, {Port.SerialBaudRate}, {Port.SerialParity}, {Port.SerialDataBits}, {Port.SerialNrOfStopBits}"); } catch (Exception e) when(e is ArgumentOutOfRangeException || e is ArgumentException || e is IOException || e is InvalidOperationException) { Sup.LogTraceErrorMessage($"Serial: Exception on Open {SensorUsed}: {e.Message}"); Sup.LogTraceErrorMessage("No use continuing when the particle sensor is not there, trying anyway..."); Valid = false; } }
public string PrepRawStreams(ulong num, bool combineDuplicateHits = false) { const UInt64 RollOverShakes = UInt64.MaxValue; string issue = String.Empty; ulong dups = 0, events = 0; Double lasttime = 0; UInt64 timeUI8B4 = 0; UInt64 timeUI8Shakes = 0, circuits = 0; double firstread = 0; try { uint chann_els = 0; foreach (double time in times) { events++; if (events > num) { events--; break; } timeUI8Shakes = Convert.ToUInt64(time); if (events == 1) { if (FirstEventTimeInShakes == 0) { FirstEventTimeInShakes = timeUI8Shakes; } firstread = time; } if (timeUI8Shakes >= RollOverShakes) // first 184467440737.09551615 ... secs are handled quickly, but here we must do a moddiv { throw new Exception("Sorry, relative event times greater 184467440737 seconds are unsupported"); } if (lasttime > time) // ooops! { throw new Exception(String.Format("{0}, {1} ({2}, {3}) out-of-order, you forgot to sort", lasttime, time, timeUI8B4, timeUI8Shakes)); } else if (timeUI8B4 == timeUI8Shakes) // found a duplicate! { dups++; if (combineDuplicateHits) { if (0 != (chann_els & channels[events])) { logger.TraceEvent(LogLevels.Verbose, 3337, "Skipping duplicate channel hit event {0} [{1:x8}] at time {2}", events, channels[events], timeUI8B4); } else { chann_els |= channels[events]; logger.TraceEvent(LogLevels.Verbose, 3331, "Combining hits [{0:x8}] from duplicate event {1} ({2})[{3:x8}] at time {4}", chann_els, NumValuesParsed, events, channels[events], timeUI8B4); } } else { logger.TraceEvent(LogLevels.Verbose, 3337, "Skipping duplicate event {0} [{1:x8}] at time {2} (due to rounding)", events, channels[events], timeUI8B4); } continue; } timeUI8B4 = timeUI8Shakes; // fill in the arrays for the analyzers chann_els |= channels[NumValuesParsed]; neutronEventArray[(int)NumValuesParsed] = chann_els; // todo: can use the skipchannels single channel flag to optimize this loop to a single increment in hitsPerChn for (short i = 0; i < NC.ChannelCount; i++) // count channel hits here { if ((neutronEventArray[(int)NumValuesParsed] & chnmask[i]) != 0) { hitsPerChn[i]++; NumTotalsEncountered++; } } timeArray[(int)NumValuesParsed] = timeUI8B4; chann_els = 0; if (!usingStreamRawAnalysis) // drop them in, one by one { Sup.HandleANeutronEvent(timeArray[(int)NumValuesParsed], neutronEventArray[(int)NumValuesParsed]); } NumValuesParsed++; lasttime = time; } logger.TraceEvent(LogLevels.Verbose, 3338, "Converted {0} hits ({1} events) between {2} and {3} shakes ({4} rollovers) ({5} duplicates skipped)({6})", events, NumValuesParsed, firstread, lasttime, circuits, dups, num); } catch (Exception e) { logger.TraceEvent(LogLevels.Verbose, 3339, "Converted {0} hits ({1} events) between {2} and {3} shakes ({4} rollovers) ({5} duplicates skipped)({6})", events, NumValuesParsed, firstread, lasttime, circuits, dups, num); logger.TraceEvent(LogLevels.Warning, 3363, "Error parsing pulses encountered '{0}'", e.Message); NC.App.Opstate.SOH = NCC.OperatingState.Trouble; issue = e.Message; } TotalEvents += events; TotalDups += dups; LastTimeInShakes = timeUI8Shakes; return(issue); }
public string PrepRawStreams(ulong num, byte[] chnbytes, bool combineDuplicateHits = false) { UInt64 ROllOverShakes = UInt64.MaxValue; string issue = String.Empty; ulong dups = 0, events = 0; uint channels = NCCFile.ByteArray.ToUInt32(chnbytes); Double lasttime = 0; UInt64 timeUI8B4 = 0; UInt64 timeUI8Shakes = 0, circuits = 0; double firstread = 0; try { foreach (double time in timeInBuffer) { events++; if (events > num) { events--; break; } timeUI8Shakes = Convert.ToUInt64(time); if (events == 1) { if (FirstEventTimeInShakes == 0) { FirstEventTimeInShakes = timeUI8Shakes; } firstread = time; } if (timeUI8Shakes >= ROllOverShakes) // first 184467440737... secs are handled quickly, but here we must do a moddiv { throw new Exception("Sorry, times greater 184467440737 seconds (about 5.8K years) are unsupported, but soon will be!"); } if (lasttime > time) // ooops! { throw new Exception(String.Format("{0}, {1} ({2}, {3}) out-of-order, you forgot to sort", lasttime, time, timeUI8B4, timeUI8Shakes)); } else if (timeUI8B4 == timeUI8Shakes) // a duplicate ! { dups++; logger.TraceEvent(LogLevels.Verbose, 3337, "Skipping duplicate event {0} at time {1} (due to hit within the same shake)", events, timeUI8B4); continue; } timeUI8B4 = timeUI8Shakes; // fill in the arrays for the analyzers if (skipchannels) { neutronEventArray[(int)NumValuesParsed] = channels; } else { channels = NCCFile.ByteArray.ToUInt32(chnbytes); } // todo: can use the skipchannels single channel flag to optimize this loop to a single increment in hitsPerChn for (short i = 0; i < NC.ChannelCount; i++) // count channel hits here { if ((channels & chnmask[i]) != 0) { hitsPerChn[i]++; NumTotalsEncountered++; } } timeArray[(int)NumValuesParsed] = timeUI8B4; if (!usingStreamRawAnalysis) // drop them in, one by one { Sup.HandleANeutronEvent(timeArray[(int)NumValuesParsed], neutronEventArray[(int)NumValuesParsed]); } NumValuesParsed++; lasttime = time; } logger.TraceEvent(LogLevels.Verbose, 3338, "Converted {0} events between {1} and {2} shakes ({3} rollovers) ({4} duplicates skipped)", events, firstread, lasttime, circuits, dups); } catch (Exception e) { logger.TraceEvent(LogLevels.Verbose, 3339, "Converted {0} events between {1} and {2} shakes ({3} rollovers) ({4} duplicates skipped)", events, firstread, lasttime, circuits, dups); logger.TraceEvent(LogLevels.Warning, 3363, "Error parsing pulses encountered '{0}'", e.Message); NC.App.Opstate.SOH = NCC.OperatingState.Trouble; issue = e.Message; } TotalEvents += events; TotalDups += dups; LastTimeInShakes = timeUI8Shakes; return(issue); }
/// <summary> /// Converts FB2 simple text /// ( simple text is normal text or text with one of the "styles") /// </summary> /// <param name="styletypeItem">item to convert</param> /// <param name="simpleTextElementConverterParams"></param> /// <returns></returns> public List <IHTMLItem> Convert(StyleType styletypeItem, SimpleTextElementConverterParamsV2 simpleTextElementConverterParams) { if (styletypeItem == null) { throw new ArgumentNullException("styletypeItem"); } var list = new List <IHTMLItem>(); if (styletypeItem is SimpleText) { var text = styletypeItem as SimpleText; switch (text.Style) { case FB2Library.Elements.TextStyles.Normal: if (text.HasChildren) { list.AddRange(text.Children.SelectMany(x => Convert(x, simpleTextElementConverterParams))); } else { if (simpleTextElementConverterParams.NeedToInsertDrop && text.Text.Length > 0) { AddAsDrop(list, text); } else { list.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } } break; case FB2Library.Elements.TextStyles.Code: var code = new CodeText(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var item in text.Children.SelectMany(x => Convert(x, simpleTextElementConverterParams))) { code.Add(item); } } else { code.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(code); break; case FB2Library.Elements.TextStyles.Emphasis: var emph = new EmphasisedText(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var item in text.Children.SelectMany(x => Convert(x, simpleTextElementConverterParams))) { emph.Add(item); } } else { emph.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(emph); break; case FB2Library.Elements.TextStyles.Strong: var str = new Strong(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { str.Add(item); } } } else { str.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(str); break; case FB2Library.Elements.TextStyles.Sub: var sub = new Sub(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { sub.Add(item); } } } else { sub.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(sub); break; case FB2Library.Elements.TextStyles.Sup: var sup = new Sup(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { sup.Add(item); } } } else { sup.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(sup); break; case FB2Library.Elements.TextStyles.Strikethrough: var strike = new DeletedText(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { strike.Add(item); } } } else { strike.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(strike); break; } } else if (styletypeItem is InternalLinkItem) { var linkConverter = new InternalLinkConverterV2(); list.AddRange(linkConverter.Convert(styletypeItem as InternalLinkItem, new InternalLinkConverterParamsV2 { NeedToInsertDrop = simpleTextElementConverterParams.NeedToInsertDrop, Settings = simpleTextElementConverterParams.Settings, })); } else if (styletypeItem is InlineImageItem) { var inlineItem = styletypeItem as InlineImageItem; if (simpleTextElementConverterParams.Settings.Images.IsImageIdReal(inlineItem.HRef)) { var inlineImageConverter = new InlineImageConverterV2(); list.Add(inlineImageConverter.Convert(styletypeItem as InlineImageItem, new InlineImageConverterParamsV2 { Settings = simpleTextElementConverterParams.Settings })); simpleTextElementConverterParams.Settings.Images.ImageIdUsed(inlineItem.HRef); } } return(list); }
public bool Has(string champ) => Mid.Has(champ) || Top.Has(champ) || Jun.Has(champ) || Adc.Has(champ) || Sup.Has(champ);