Leaderboard style query in GORM for a Groovy/Grails app - grails

I have a Grails app in production where we will be implementing a leaderboard. Let's say that the users are playing rock-paper-scissors and the leaderboard is tallying wins, losses and ties. That's fine, no problem. But now our user base has become large enough that a person would have to scroll and scroll and scroll to find where they are in the list. What we'd like to do is show the top 10 or so in the leader board (this is being displayed on an iPhone btw) and then the user's name with their rank against everyone else like this:
Andrew
Bruce
Charlie
Doug
...
3,194 YOU
I know this can be achieved by doing a query for the complete list and then calculating the position but that seems expensive to perform every time. One alternative I thought about was just running that query from a quartz job and saving everyone's current position in the leaderboard so it's easily accessible. I'm not in love with that either because then it's not going to be a real time answer.
I think what I'm looking for is a GORM way to almost do an indexOf for a single record among its peers based on the query criteria.

Related

Vacation tracker

So I have an issue I cannot wrap my brain around. I am creating an employee vacation tracker, and I have already multiple sheets with different data, i.e. one consists of Google Form answers about when the employee wants to take time off work for holidays. Please note that I also already have data on employee availability each standard day of the workweek.
Alright, onto the problem. Let's say 'Lukas' is a part-time employee and only works Tuesdays, Wednesdays, and Fridays. He sends in his vacation plan: he will be enjoying the seaside from 1.8. until 15.8. How on earth can I combine multiple sheets and data in such a way, to only count his holidays by his actual workdays? I can not even begin to write the formula - this is where I should note I am a beginner at Sheets.
Alright - I took a look at your mock-up sheet, I must admit it's still felt somewhat unorganized.
Due to the lack of enough dummy data and without being certain whether or not you empty/refresh the weekly availability tabs (I'd recommend you not to do so), it wasn't fully clear what you wanted.
Nonetheless, I couldn't resist, I've been working on several projects and your topic gave me some creative inspiration, so I went ahead and did a major rebuild in your mock-sheet.
Should you want to use or implement it, here's some info good to know:
The Employees tab is meant as an input field for any coming and going employees; just add any names there and they will be automatically added to the main schedule.
I mocked some more data, so the output might not be what you expected, but;
In the Holiday overview tab you can see all employees with the days they've taken, planned, and left.
In the Schedule Dashboard tab, you will find three main sections.
The working schedule based on the data from the Weekly Availability tab of which I guess you manually move over data to from the Availability Responses tab.
The Holiday schedule; this fully takes into account whether or not it overlaps with a supposed working day, or if the person was off already anyhow. Therefore; Holiday is shown when it overlaps with a scheduled working day and Day Off is shown when it doesn't. Only the Holidays are deducting the remaining holidays.
The right one I did based on my own experiences; it works like an alerting sign that whill show you if holidays are approved while still being scheduled, where I work we do this the other way around. Holiday Request > We unschedule > We approve holidays > No overlaps should exist.
I posted some comments in the sheet here and there on orange tiles.
Curious to know if this helped!

Rails: How to query records in different languages

I have a Rails inventory app that is available to global users, allowing them to enter their own inventory information and query those of others.
a British person in London adds 10 units of "bicycle" to the inventory table
a Japanese person adds 2 units of 自転車 (bicycle in Japanese)
a Vietnamese adds 5 units of xe dap (bicycle in Vietnamese)
The British person can query 'bicycle' and it will output all bicycles in the system (17 units) and can show the details of each in their original language, without the users classifying them beforehand. Likewise, the Japanese person can query '自転車', which will show all bicycles.
How can this be done?
The globalize gem requires users to manually translate each record so it's not the correct way. I've heard about machine learning and deep learning but I don't know if it's the right solution for this.
So if stackoverflow is not the right place to ask this? Where should I ask? Quora does not allow long questions.
Machine learning does not seem like a proper solution in this context since you don't have enough experience with it and it's a complex matter to just start with it and learn enough to apply to a real life problem.
Here are a few solutions you could implement today, as long as you understand the requirements and the up/downs for each, you will have to figure those out by yourself.
Since I don't have enough information about your system I'll try and generalize it to something that's likely.
Solutions:
1.Define a limited number of items for your system, like Bike and add
them to a config file or in a items database, each item having it's
unique id and when a user will have to add something they will have
to select from your list. Have a Other item as a catch-all, and
maybe provide a note so the users can add anything to recognize the
item.
2.Similar to the above solution but you give the users a way to add new items into the system, so you have 10 standard items and every user can add items to the site (those being moderated) and other users will have access to them.
3.Have a solid search system in place like Elasticsearch (or anything else), and when the user create items you index that item in the language that is entered, and then use Google translation API (or another translation service) to translate them in all the languages you need and index those for search as well.
I think solution 1 is the best if you are able to implement it followed by solution 2.

Firebase - App developing - calculate the delta without generating a high data traffic

We are developing a social app with Firebase (swift / iOS).
We face the problem that we have two data trees and have to calculate the delta without generating a high data traffic.
Example:
We have a structure cars and a structure user.
The structure cars contain 100 different vehicle models.
The user structure contains all vehicle models that have already been driven by the user.
We now want to implement a high-performance solution in order to determine all the vehicles that have not yet been driven by a user without downloading the whole tree structure.
The number of users and the number of vehicles are growing steadily.
Does anyone have a solution approach or idea in which direction we need to think?
love, alex
I think they key to effectively using firebase is data duplication. So if you want to display a list of cars the user has and hasn't driven, create a separate table containing only the information displayed in that list, like the path to an image, the make & model, using unique IDs as the keys to entries in that table. You wouldn't need to know things like top speed and price until they tap into details, right? (I'm making some assumptions here though.)
Then, simply get the list of unique IDs for the cars the user already has driven, and manipulate your offline model accordingly.
Right now I'm using an external server to manage data duplication, that propagates a write operation to other places in the database when necessary. I'm on my phone right now but I think Ray Wenderlich has an article about this.

Save game/user statistic in a central database with swift and sql on IOS 8

I am making a game for IOS 8 using the Swift language. For each level I was planning to save data such as how long it takes to solve the level, what (x,y) position a player dies, how many attempts before solving the level etc. I will then use this information to improve the game by adjusting the difficulty of levels.
So I figured I would have a simple SQlite DB stores locally with this information. And then I wonder how I should upload this information to one central database. Any ideas?
For example, what kind of unique identifier can I use? I don't care about the individual data, just the average time to complete a level and the average nr of attempts to solve a level..
But, if I have in-app purchases, how can a user that delete the app, or get another iphone restore the purchases made? This is again related to a unique identifier that is connected to the user, not just the iphone.
You really should be using analytics tools to do this. I would recommend using Flurry. Its free to use, and goes into your game very easily.
http://www.flurry.com/solutions/analytics
I have used it in a number of products. You can send in the anonymous data you want based on events. So every time a level is complete, you can report it to flurry as an event, and pass parameters of level, score, and completion time.
You can look at a nice dash board to see the results and averages.
Its easy to incorporate it into a Swift app. Another SO answer goes through this in detail.

NLP for extracting actions from text

I'm hoping somebody can point me in the right direction to learn about separating out actions from a bunch of text.
Suppose I have this text
Drop off the dry cleaning, and go to the corner store and pick-up a jug of milk and get a pint of strawberries.
Then, go pick up the kids from school. First, get John who is in the daycare next to the library, and then get Sam who is two blocks away.
By the time you've got the kids, you'll need to stop by the doctors office for the perscription. Tim's flight arrives at 4pm.
It's American Airlines flight 331 arriving from Dallas. It will be getting close to rush hour, so make sure you leave yourself enough time.
I'm trying to have it split up into
Drop off the dry cleaning,
and go to the corner store and pick-up a jug of milk and get a pint of strawberries.
Then, go pick up the kids from school. First, get John who is in the daycare next to the library, and then get Sam who is two blocks away.
By the time you've got the kids, you'll need to stop by the doctors office for the perscription.
Tim's flight arrives at 4pm.
It's American Airlines flight 331 arriving from Dallas. It will be getting close to rush hour, so make sure you leave yourself enough time.
I haven't been able to find anything in my searches that is specifically action based. It would need to be smarter than just picking out verbs, as there are multiple verbs that are sometimes associated with one action for, instance the second item has 'go','pick-up' and 'get', but that is all part of a single action. Of course, "Tim's flight" is only suggests an action with the present participle, with the verb coming toward the end of the segment.
Any suggestions on where to look to do this kind of thing? Things to watch-out for, recommended readings, etc. etc.
Simple approach: parse the text using [your favorite parser], then select the sentences or SBAR phrases that are in the imperative mood. The Stanford Parser just so happens to have "Improved recognition of imperatives" in its very latest release.
There's probably no need for machine learning beyond what is already incorporated in standard parser programs.
This domain is called Information Extraction.
The general approach to sentence understanding is either:
extract a Part-Of-Speech tagged parse-tree (Python spaCy.io, nltk, CoreNLP etc.)
extract a word-vector (e.g. word2vec)

Resources