How to specify a range of valid values in a Java GUI - java

I am creating an IMDB application which displays and organizes movies found on you computer (by looking up the metadata via an IMDB API).
In my search panel I want to give the user the option of looking for movies that were released in a specific range of years (e.g. between 1990 and 2005). Currently I use for this two JSpinners, one for the minimum year and one for the maximum year and use cross validation to check whether maxYear >= minYear && minYear <= maxYear However I don't think this is very user-friendly.
What I would like is a JSlider with two knobs, one for min and one for max. Is this possible? Do you have any other ideas on how to make this interface more user-friendly?

This looks promising: Creating a Java Swing range slider
And here's another example that I think came from the old Tame examples: MThumbSlider

You could have two JTextFields, and just let the user type the minimum and maximum years.
Otherwise, two JSpinners is another choice. Developing a custom component that your users have never seen is not user friendly.
You can cross connect the two JSpinners so that it's impossible for the user to enter a minimum year greater than a maximum year. I've not done this, so I don't have a code example to show you.

Related

Java - statistics automation using arrays, (Creating a table of classes)

I know this is kind of hard to understand but bear with me here, I'm taking a statistics class and I wanted to automate the process, so what we do is take some data, take the minimum number and maximum, get the range, all easy and already done.
But here is the trick, we need to split the data between classes, for example user entered 10 data points ranging between the numbers 10 and 40, what you wanna do is create classes to fit each number, class one is the numbers between 10 and 15, class 2 is 15 and 20 and so on (this was just an example).. thinking about it first you can just make a shit ton of if conditions, but that doesn't seem intuitive and second all data and class width and number of classes are the user's choice, so how do you suggest I approach this problem?
To help you understand here is a better example:
STATS

Java retrieve and compare two dates plus time

Basically I want to ask the user for a date and time of departure then ask the user for time of arrival to compare and get duration. I was wondering what kind of method of input would be good for this input. I was thinking either a multi drop down box or some kind of scrolling bar type deal. Can any one give me and suggestion on a good input method and what it is called? That does not require adding components or just asking the user to type it in, something simple.
Yes, using two dropdown controls (or a calendar control for the date) is a common way of handling this in a GUI.
Search Google for ideas, for example amtrak.com, or any travel website really.

Populate data in Listview on Weekly basis in android

I have to display data in Listview in android. For that I am retrieving data from sqlite database, having two column fields "date" and "amount". There are some more column fields but i don't need them. Now I want to show data in Listview weekly basis, with addition of the amount for the given week. Can anyone Please help me. How can I do this.(I thought of using strftime() function also but it add all the previous weeks data in one row. even thought for using Calendar class of java but don't know how can I achieve the solution using that.)
If I understand correctly your only problem is to make sure that a week has passed. If so:
I refer you to this solution: (Java / Android) Calculate days between 2 dates and present the result in a specific format , that uses no external Java libraries. You can just save the former list population day, the current day, and use the solution here to get the distance between them in days. Then all that remains is to check if the result >= 7. if so, a week has passed.

How to discard time intervals with Time Series / XYPlots using JFreeChart?

I am building a set of chart displays, one of which is for a month display of daily trading - that is, one point of data per day (closing).
Since there is no trade during weekends and holidays, I need to discard these data points. Not only that, but data points should still appear adjacent to each other, regardless of any gaps in time. This can be seen in any such chart e.g. in the 3 month graph for Nasdaq on Yahoo Finance - see how weekends are skipped.
My question is: how should one correctly implement this in JFreeChart?
Thanks in advance!
In addition to omitting the excluded data points, you can apply a SegmentedTimeline to the corresponding DateAxis. For example,
axis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
Although deprecated in the current version, as discussed here, the implementation may guide creation of a custom TimeLine, as noted in a comment here.

Is there a good algorithm to check for changes in data over a specified period of time?

We have around 7k financial products whose closing prices should theoretically move up and down within a certain percentage range throughout a defined period of time (say a one week or month period).
I have access to an internal system that stores these historical prices (not a relational database!). I would like to produce a report that lists any products whose price has not moved at all or less than say 10% over the time period.
I can't just compare the first value (day 1) to the value at the end (day n) as the price could potentially have moved back to what it was on the last day which would lead to a false positive while the product's price could have spiked somewhere in between of course.
Are there any established algorithms to do this in reasonable compute time?
There isn't any way to do this without looking at every single day.
Suppose the data looks like such:
oooo0oooo
With that one-day spike in the middle. You're not going to catch that unless you check the day that the spike happens - in other words, you need to check every single day.
If this needs to be checked often (for a large number of interval, like daily for the last year, and for the same set of products), you can store the high and low values of each item per week/month. By combining the right weekly and/or monthly bounds with some raw data at the edges of the interval you can get the minimum and maximum value over the interval.
If you can add data to kdb (i.e. you're not limited to read access) you might consider adding the 'number of days since last price change' as a new set of data (i.e. one number per financial instrument). A daily task would then fetch today's mark and yesterday's, and update the numbers stored. Similarly you could maintain recent (last month, last year) highs and lows in kdb. You'd have to run a job over the larger dataset to prime the values initially, but then your daily updates will involve much less data.
Recommend that if you adopt something like this you have some way to rerun for all or part of the dataset (say for adding a new product).
Lastly - is the history normalised against current prices? (i.e. are revaluations for stock splits or similar taken into account). If not, you'd need to detect these discontinuities and divide them out.
EDIT
I'd investigate usng kdb+/Q to implement the signal processing, rather than extracting the raw data to a Java application. As you say, it's highly performant.
You can do this if you can keep track of the min and max value of the price during the time interval - this assumes that the time interval is not being constantly changed. One way of keeping track of the min and max values of a changing set of items is with two heaps placed 'back to back' - you could store this and some pointers necessary to find and remove old items in one or two arrays in your store. The idea of putting two heaps back to back is in Knuth's Art of Computer Programming Vol 3 as Exercise 31 section 5.2.3. Knuth calls this sort of beast a Priority Dequeue, and this seems to be searchable. Min and max are available at constant cost. Cost of modifying it when a new price arrives is log n, where n is the number of items stored.

Categories