Searchbox with Reactive Extensions and textbox Textchanged event - winforms

I'm having troubles building a searchbox with reactive extensions.
My goal is to get the latest text available every X milliseconds, do my search and post results back on a UI grid (winforms). But i'm stuck with first step.
I can see by logging that multiple events are fired in 5000 milliseconds using Rx Sample, not only one! I expected 1 time every 5000 ms max.
My code is really simple and i strongly believed it worked:
EventLoopScheduler scheduler = new EventLoopScheduler(ts => new Thread(ts));
Observable.FromEventPattern<EventArgs>(this.textBox1, "TextChanged")
.Sample(new TimeSpan(5000), scheduler).ObserveOn(this).Subscribe
(
args =>
{
string text = ((TextBox)args.Sender).Text;
Console.WriteLine("Sample fired. Text: {0}", text);
}
);
I'm wiring up everything in the constructor of a Form.
Am i messing up with scheduler?
Thank you.

Instead of new TimeSpan(5000) which is 5000 ticks and not very long at all, use TimeSpan.FromSeconds(5).

Related

How to sessionize / group the events in Akka Streams?

The requirement is that I want to write an Akka streaming application that listens to continuous events from Kafka, then sessionizes the event data in a time frame, based on some id value embedded inside each event.
For example, let's say that my time frame window is two minutes, and in the first two minutes I get the four events below:
Input:
{"message-domain":"1234","id":1,"aaa":"bbb"}
{"message-domain":"1234","id":2,"aaa":"bbb"}
{"message-domain":"5678","id":4,"aaa":"bbb"}
{"message-domain":"1234","id":3,"aaa":"bbb"}
Then in the output, after grouping/sessionizing these events, I will have only two events based on their message-domain value.
Output:
{"message-domain":"1234",messsages:[{"id":1,"aaa":"bbb"},{"id":2,"aaa":"bbb"},{"id":4,"aaa":"bbb"}]}
{"message-domain":"5678",messsages:[{"id":3,"aaa":"bbb"}]}
And I want this to happen in real time. Any suggestions on how to achieve this?
To group the events within a time window you can use Flow.groupedWithin:
val maxCount : Int = Int.MaxValue
val timeWindow = FiniteDuration(2L, TimeUnit.MINUTES)
val timeWindowFlow : Flow[String, Seq[String]] =
Flow[String] groupedWithin (maxCount, timeWindow)

Devexpress: how to add points to Chart Control at runtime?

i'm trying to build a telemetry software using Winform and Devexpress library. Specifically i'm working on a Line Chart Control and what i would like to do is to configure the chart so that it is able to display a data changing in real time.
The graph is generated reading some external sensors that send informations at a rate of 10 values per second.
This is my code for initialize the chart:
series1 = new Series("test test", ViewType.Line);
chartControl1.Series.Add(series1);
series1.ArgumentScaleType = ScaleType.Numerical;
((LineSeriesView)series1.View).LineMarkerOptions.Kind = MarkerKind.Triangle;
((LineSeriesView)series1.View).LineStyle.DashStyle = DashStyle.Dash;
((XYDiagram)chartControl1.Diagram).EnableAxisXZooming = true;
chartControl1.Legend.Visibility = DefaultBoolean.False;
chartControl1.Titles.Add(new ChartTitle());
chartControl1.Titles[0].Text = "A Line Chart";
chartControl1.Dock = DockStyle.Fill;
And this is the one that add a new point and remove the first point available so that the amount of points in my chart is always the same (after a minimum amount of points is reached) and it keeps updating itself displaying the last X seconds of values and discarding the old values.
series1.Points.RemoveRange(0, 1);
series1.Points.Add(new SeriesPoint(time, value));
...
AxisXRange.SetMinMaxValues(newFirstTime, time);
AxisRange is the following
Range AxisXRange
{
get
{
SwiftPlotDiagram diagram = chartControl1.Diagram as SwiftPlotDiagram;
if (diagram != null)
return diagram.AxisX.VisualRange;
return null;
}
}
**The problem ** is that this code works temporarily. After some seconds, the chart stop working and a big red cross is displayed over it.
Is there something that i'm missing with its configuration?
Do you know any better way to realize my task?
Any help would be appreciated.
Thank you
I think you doing it nearly right. Devexpress has an Article about RealTime-Charts. They doing it the same way but using a timer for updating the data. Maybe this would fix your painting problems.

Using "tick" event delta to create timer but it's running too fast

I am using the "tick" event's delta property in EaselJS in order to create a simple timer in milliseconds. My ticker is set to 60 FPS. When the game is running I am getting roughly 16/17 ms between each tick (1000/60 = 16.6667) - so I am happy with this. However, when I append this value onto my text value (starting from 0) it is going up considerably quicker than it should be. I was expecting that on average it would be displaying a time of 1000 for each second elapsed. My code (in chunks) is below (game.js and gameInit.js are separate files). I am hoping that I am just overlooking something really simple...
//gameInit.js
createjs.Ticker.setFPS(60);
createjs.Ticker.on("tick", this.onTick, this);
...
//game.js
p.run = function (tickerEvent) {
if (this.gameStarted == true ) {
console.log("TICK ms since last tick = " + Math.floor(tickerEvent.delta)); // returns around 16/17
this.timerTextValue += Math.floor(tickerEvent.delta); //FIXME seems too fast!
this.timerText.text = this.timerTextValue;
}
};
Kind Regards,
Rich
Solved it. What a silly mistake! So, I had another place where I was initialising the ticker meaning it was being invoked twice, hence the reason that my timer was displaying doubly quick

Temporarily suspend data-binding in AngularJS to update model without firing $scope.$watch

UPDATE 4/19/2012 12PM PST: Gotta eat crow on this one. The problem was not with Angular's databinding but with math errors in how I was calculating the dates. I wasn't properly taking into account the minutes and seconds in my time calculations. I was just subtracting the timestamps from each other expecting the hours to come out nicely.
I've gotten myself into trouble with AngularJS databinding in which my different inputs need to be reciprocally bound to each other.
The form needs to contain the following:
A start date (this is a given, not an input)
An input to add hours on to the start date
Two inputs with the result: 1) a date picker and 2) an hour picker
If you change any of the inputs, it should update the others. So, the following would be desirable results:
(with original date-time as April 19th at 10pm). User enters '1 hour'. The result date becomes April 19th and the result time becomes 11pm.
Building on the above example, the user changes the date input to April 20th. The 'hours' now become 25 hours.
I've placed set up watchers, using $scope.$watch on each of these variables:
$scope.$watch('hours', function (newHours, oldHours, scope) {
if (newHours) {
var newEndDate = new Date(scope.origDate),
offHours = newEndDate.getHours();
newEndDate.setHours(offHours + newHours);
scope.endDate = newEndDate;
scope.endHours = newEndDate.getHours();
}
});
$scope.$watch('endHours', function (newEndHours, oldEndHours, scope) {
if (newEndHours) {
var newEndDate = new Date(scope.endDate);
newEndDate.setHours(newEndHours);
scope.endDate = newEndDate;
}
});
$scope.$watch('endDate', function (newEndDate, oldEndDate, scope) {
if (newEndDate) {
scope.hours = (newEndDate - scope.origDate) / (1000 * 60 * 60);
}
});
Each of these works fine on their own, but in tandem they cause a big fat mess. From my understanding of Angular, it seems that they're creating a 'feedback loop.' Edit: To wit, model 'A' will be updated and trigger a change on model 'B'. Model 'B' will then trigger a change on model 'A'.
Now, is it possible to temporarily suspend data-binding so that I can just update the models without firing the watchers? In some other contexts I've worked in (UITableView on Cocao comes to mind), one can ask to "stop updates," make some changes to the model, and then "resume updates."
Is there anything like this in AngularJS? If not, what am I not getting here, and how could I set up my project to achieve the desired functionality?
Here's a plunkr of my example.

Visual Studio timer problem

I couldn't find any explanation for the following problem. Hope you to help me to know the solution...
Let's make a new windows appliaction (using any version of VS), and add a button, timer (we modify the interval to become = 10), and a label (with initial text = "0").
write the following code in the timer:
label1.Text =
(Convert.ToInt32(label1.Text) +
1).ToString();
write the following code in the button:
timer1.Enabled = true;
The label should show an incremental counter starting from 0.
Logically, each 100 counts should consume 1 second, but this is NOT the truth.
What happens is that each 100 counts consume a little bit more than 1 second !!!
What is the cause of this behavior????!!!
Thank you very much for your listenning, and waiting for your reply because I really searched for an explenation but I couldn't find anything.
If you are using System.Windows.Forms.Timer, it is limited to an accuracy of 55 ms.
The Windows Forms Timer component is single-threaded, and is limited to an accuracy of 55 milliseconds. If you require a multithreaded timer with greater accuracy, use the Timer class in the System.Timers namespace.
See the Remarks section: System.Windows.Forms.Timer

Resources