Return one of each value Parse.com Query - ios

I have a class Event. Each Event has an EventParent, and an EventName.
What I am looking to do is write a query that returns each unique EventParent once.
EventParent| EventName
NY Sports | MSG
NY Sports | Barclays
CA Sports | Staples Center
CA Sports | Oracle Arena
In the above example, I'd like to get NY Sports and CA Sports as my result. What is the best way to do this using a Parse query?

Related

Grading Google Classroom assignments using Google Sheets

I am trying to grade a Google classroom of about 200 students and I have succeeded in grading each student on a .csv file. Is there a method that allows you to automatically fill and submit grades and comments on Google Classroom from a Google Sheet?
I have tried reading the .csv file and that works fine in a Python Script but writing the data to Google Classroom has been an issue.
With the Classroom API you should be able to push grades to your Course if you have either the student IDs or student emails in the Google Classroom to match on. You can't, however, push comments.
The workflow for pushing grades would be as follows:
If you don't have the Classroom course ID, retrieve it via the courses.list endpoint. Keep this handy for future use.
With the Course ID from step 1, create a CourseWork item via
the coursework.create function. You'll have to do this for each assignment you have. Make sure you keep the CourseWork IDs associated with each assignment for future reference.
If you only have the student emails, you'll have to get their Classroom IDs with the students.get endpoint. This will also need the Course ID from step 1.
Each CourseWork has a student submission object for each student, so you'll need to collect these student submission IDs for each student for the assignment. You can do this with the studentsubmissions.get endpoint.
With each of these student submission IDs, push the student's grade for the given assignment with the studentsubmissions.patch endpoint. You'll need the course, coursework, and studentSubmission IDs to push this grade.
Finally, return each of these grades with the studentsubmissions.return endpoint. Again, you'll need the course, coursework, and student submission IDs for this.
If you're using a spreadsheet, I imagine an example structure with all the data needed to do this would like as follows:
| Student Email | Student ID | Assignment 1 ID | Submission ID | Assignment 1 Grade |
| ------------- |:-------------:|:----------------:| ----------------:| ------------------ |
| Email 1 | student id 1 | courseWork 1 ID | submission 1 ID | grade #1 |
| Email 2 | student id 2 | courseWork 2 ID | submission 2 ID | grade #1 |
| ... | ... | ... | ... | ... |
Columns 3, 4, and 5 would repeat for each assignment you have. Documentation on how to write this code can be found here and here. If you're using Google Sheets, you can make an Apps Script to do all of this.
As for the comment functionality, again, we don't support that right now, but I encourage you to you can follow the reported feature request for updates here. I also recommend clicking “Me too!” at the top of the listed issue and posting any comments regarding your use case + need.
Hope this helps!

Neo4j - Can't load all fields from CSV

This is my load command:
neo4j-sh (?)$ USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:/Users/levi/data/woka-data/atom_description.csv" AS row
CREATE (:Description {language: row.content.language, value: row.content.value, woka_id: row.woka_id});
This are the first couple rows in my CSV file (first line is the header):
content.language,content.value,woka_id
"eng","This handbook is the first of its kind to discuss infection control guidelines that directly relate to surgical environments. It is particularly useful to nurses who need to meet OSHA and JCAHO requirements for practice in perioperative, PACU, ambulatory, and endoscopy settings. Procedure guidelines are concisely described and followed by rationales referenced to AORN standards, CDC guidelines, and other resources.","97800000003300000000"
"eng","Practitioners and academics dealing with the Middle East can turn to the Yearbook of Islamic and Middle Eastern Law for an instant source of information on the developments over an entire year in the region. The Yearbook covers Islamic and non-Islamic legal subjects, including the laws themselves, of some twenty Arab and other Islamic countries. The publication's practical features include: <br>- articles on current topics, <br>-country surveys reflecting important new legislation and amendments to existing legislation per country, <br>- the text of a selection of documents and important court cases, <br>- a Notes and News section, and<br>- book reviews. <br>","97800000222400000000"
This is what was effectively loaded in the db:
neo4j-sh (?)$ match (n: Description) return (n) limit 10;
+------------------------------------------------+
| n |
+------------------------------------------------+
| Node[26293467]{woka_id:"97800000003300000000"} |
| Node[26293468]{woka_id:"97800000222400000000"} |
| Node[26293469]{woka_id:"97800000255240000000"} |
| Node[26293470]{woka_id:"97800002099930000000"} |
| Node[26293471]{woka_id:"97800002966650000000"} |
| Node[26293472]{woka_id:"97800010161180000000"} |
| Node[26293473]{woka_id:"97800010161320000000"} |
| Node[26293474]{woka_id:"97800010161560000000"} |
| Node[26293475]{woka_id:"97800010162170000000"} |
| Node[26293476]{woka_id:"97800010162310000000"} |
+------------------------------------------------+
10 rows
27 ms
What I am missing here?
You should not have dots in the csv's header field. Replace them e.g. by underscore, both in the header line and in the LOAD CSV command.

partition PostgreSQL table based on geometry column

Here is the table with geometry field :
Table "public.regions"
Column | Type |
-----------+-----------------------+-
id | integer |
parent_id | integer |
level | integer |
name | character varying(55) |
location | geometry |
I have stored the geometry for all continents, countries , states and cities. Since it is a huge table I need to partition the table based on top level location ( i.e continent) to improve the performance .
How can I partition my existing table based on geometry(continent) ? Is it good enough to create inheritance tables named asia, europe, australia ... and insert rows in those tables based on queries with contains ? Will that improve the performance of my queries?
For eg. I am trying to run queries like :
11.562424 48.148679 is some point in Munich
EXPLAIN ANALYZE SELECT id, name,level FROM regions WHERE
Contains((location),(GeomFromText('Point(11.562424 48.148679)')));
This is taking around 500 ms with PG in my computer whereas the same query is taking around 200ms in Oracle.

How to make selection content an attribute for a Rails model

I am having a hard time even formulating the question I want to be answered, so here's my situation:
I'm trying to make a simple stock market plotter tool using an existing database I populate elsewhere. My app already has a nice and dynamic plotter that works with any database, but it expects data in a certain way. So say my model (database) looks like this:
Stock:
|___ticker___|___open___|___close___|___date___|
| aapl | 100 | 101 | 1/1/11 |
| aapl | 101 | 102 | 1/2/11 |
| goog | 500 | 450 | 1/1/11 |
| goog | 450 | 451 | 1/2/11 |
...
My plotter routines work off of class attributes (I think thats the terminology), which correspond to columns in the database.
I can select all the data corresponding to 'aapl', and easily plot the open and close versus date since my model has said attributues.
#stock = Stock.select_by_ticker('aapl')
>> #stock.open #=> 100 ...
>> #stock.close #=> 101 ...
>> #stock.date #= 1/1/11 ...
so the attributes would be
{open, close, date}
But if I want to compare say the closing price for different stocks, I need attributes pertaining to each stock. So basically I want to end up with a model with ticker names as attributes, each corresponding to that ticker's hunk in the database. Using easy to build scopes, I want something like:
#stock = Stock.select_close_by_ticker('aapl','goog')
attributes are:
{aapl, goog, date}
where aapl and goog contain the closing price data for just that ticker. I can run multiple database queries if I need to, for now I just want to be able to sort my data into this form. Also, it must be completely dynamic, so I can't hardcode 'aapl', 'goog' and all the millions of other tickers into my model.
Would something like:
stocks = ['appl', 'goog']
Stock.find(:conditions => ['ticker in (?)'], stocks)
work for your scenario?

Cassandra cql kind of multiget

i want to make a query for two column families at once... I'm using the cassandra-cql gem for rails and my column families are:
users
following
followers
user_count
message_count
messages
Now i want to get all messages from the people a user is following. Is there a kind of multiget with cassandra-cql or is there any other possibility by changing the datamodel to get this kind of data?
I would call your current data model a traditional entity/relational design. This would make sense to use with an SQL database. When you have a relational database you rely on joins to build your views that span multiple entities.
Cassandra does not have any ability to perform joins. So instead of modeling your data based on your entities and relations, you should model it based on how you intend to query it. For your example of 'all messages from the people a user is following' you might have a column family where the rowkey is the userid and the columns are all the messages from the people that user follows (where the column name is a timestamp+userid and the value is the message):
RowKey Columns
-------------------------------------------------------------------
| | TimeStamp0:UserA | TimeStamp1:UserB | TimeStamp2:UserA |
| UserID |------------------|------------------|------------------|
| | Message | Message | Message |
-------------------------------------------------------------------
You would probably also want a column family with all the messages a specific user has written (I'm assuming that the message is broadcast to all users instead of being addressed to one particular user):
RowKey Columns
--------------------------------------------------------
| | TimeStamp0 | TimeStamp1 | TimeStamp2 |
| UserID |------------|------------|-------------------|
| | Message | Message | Message |
--------------------------------------------------------
Now when you create a new message you will need to insert it multiple places. But when you need to list all messages from people a user is following you only need to fetch from one row (which is fast).
Obviously if you support updating or deleting messages you will need to do that everywhere that there is a copy of the message. You will also need to consider what should happen when a user follows or unfollows someone. There are multiple solutions to this problem and your solution will depend on how you want your application to behave.

Resources