Eleventy + Airtables custom url structure for products - airtable

I have a table in Airtable that contains rows of products that for the sake of brevity have these 4 fields.
Product Name | Category 1 | Category 2 | Category 3
Iam trying to figure out how I can build the following url structure upon build when all products are fetched via the Airtable API.
www.sitename.com/products/category1 and list all products that are in this category
www.sitename.com/products/category1/category2 and list all products that are in this category
www.sitename.com/products/category1/category2/category3 and list all products that are in this category
I need some pointers in how to set this up. I tried googling for an answer but had no good results.
Thank you!

Related

Product recommendation cypher

I have the following simple graph -
I wish to build a simple recommendation system on the basis of the following example:
Consider that we have invoice 1 with an Article "Apple".
We also have invoice 2 which has "Apple" and "Oranges".
Customer of invoice 1 should be recommended "Oranges".
Basically, When a customer adds an item to an invoice, we need to recommend articles that were added to another invoice with at least one of its article in the current invoice. And the recommended article not in the current invoice.
Another way to say this -
When an article A exists in Invoice 1 AND Invoice 2 also contains article A, then list all other articles in Invoice 2 provided they do not exist in Invoice 1.
However, as a complete beginner I'm unable to figure out how to write the cypher query. Any help on how to write such a query?
Something like below should work to start with:
MATCH (i:Invoice)-[]-(a:Article)-[]-(:Invoice)-[]-(b:Article)
WHERE i.invoiceNumber = 123
RETURN b;
What is does is - start from the invoice, then navigate through the articles connected to that invoice, onto other invoices (all other invoices that share this article). From there it collects all the articles connected to those invoices.
(this assumes that you are using unique Articlenodes and connecting the invoices to them)
You can use below query for a given Customer (let say Customer1), give me other customers and recommended food based on any food that Customer1 ordered and common to other customers.
MATCH (c1:Customer {name: 'Customer1'})<-[:GENERATED_FOR]-(:Invoice)<-[:ITEMIZED_IN]-(:Article)-[:TYPE]->(f:FoodArticle)
WITH c1, collect(f) as food
MATCH (c2:Customer)<-[:GENERATED_FOR]-(:Invoice)<-[:ITEMIZED_IN]-(:Article)-[:TYPE]->(f2:FoodArticle)
WHERE c1 <> c2 AND f2 in food
WITH c2, food, collect(f2) as food2
WITH c2, [fd IN food WHERE NOT fd IN food2] as recommendations
WHERE size(recommendations) > 0
RETURN c2.name, recommendations
First, get all food that customer1 has ordered
Next, find all customers that has at least one food contained in Customer1's food
List out customer2 and collect all food for this customer2
Create a list of recommended food based on those found in customer1 food list BUT NOT found in customer2 food list
Return customer2 name and recommended food but ensure that there is at least one food in Customer1 list that is not found in customer2 list (food2)

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!

How to show 3 nested tables in Google Data Studio?

I am looking for a way to combine 3 Tables:
Contract | Invoice | Payments
with relations 1:n between them, for example:
I have 3 sheets: Contract, Invoice, Payments, with IDs; for simplicity, shown below are only the ID columns:
Contract Invoice Payments
-------- ------- ---------
Contract1 Invoice10 Payment101
Contract1 Invoice10 Payment102
Contract1 Invoice11 Payment103
Contract2 Invoice12 Payment104
Contract2 Invoice13 Null
Contract3 Null Null
I want to create 3 Linked Tables in the Same Page:
When I select one Contract, the other tables only show data related to this Contract, and after I select one Invoice, then the table of Payments only shows data related to this Invoice.
The only way that I found about was blending 3 tables, however, I would need the same key fields (Join Keys) in all tables, but that is not in my case.
=IFERROR(QUERY({A1:A, B1:B, C1:C},
"where Col1='"&F1&"'
and Col2='"&F2&"'", 0),
"no match")
demo spreadsheet

Sqlite3: Selecting from multiple tables without duplicates

I've got three tables:
paper: items: attachments:
============ ============== ==============
jkey | title itemID | jkey* itemID* | path
*foreign key from another table
I'm trying to retrieve the title of all papers and their associated attachment paths, for all papers that have attachments.
Current attempt is:
SELECT paper.title,attachments.path IN paper,attachments
WHERE paper.jkey IN (
SELECT items.jkey FROM items,attachments
WHERE items.itemID = attachments.itemID
);
Unfortunately this just seems to print gibberish (the same path for different titles and vice versa).
What am I doing wrong?
If you want to join, you should use joins:
SELECT paper.title,
attachments.path
FROM paper
JOIN items USING (jkey)
JOIN attachments USING (itemID);
To omit duplicate rows, use SELECT DISTINCT ... instead.

How to get unique product list?

We have list of category products having duplicate names.
How to get a list of products which should not have duplicate product name in Postgres?
We are searching for min product ids with group by name.
then searching the products in ids.
category = Category.first
ids = Product.select("MIN(id) as id").where(deleted: false).group(:name).collect(&:id)
category.products.where("products.id IN (?)", ids).find_active
How can we optimize the queries?
You can do Product.all.pluck(:name).uniq to get just the product names in an array.
But I think you're solving the wrong problem, in that this problem has a bad 'smell'. If you have products that have identical names, how do you differentiate them from a UX perspective? And why only get the first created product by that name vs. the most 'popular' product? I'm trying to imagine how this solution would work for the user and I'm coming up blank, perhaps because I don't know enough about the context.
Edit: Also, could you clarify what you mean by 'should not have duplicate product name'? Is it to get a list of products, but only the first product if there's multiple products with the same name? Or are you looking for items to correct?
The simple solution in Postgres is with DISTINCT ON:
SELECT DISTINCT ON (name)
id, name -- add more columns if you need
FROM Product
WHERE deleted = FALSE
ORDER BY name, id;
Returns unique product names (sorted alphabetically). From each set of dupes the one with the smallest id. Details:
Select first row in each GROUP BY group?

Resources