robertszafa / moodportfolio

2 stars 1 forks source link

Tag Graph SQL #39

Closed DevGareth closed 5 years ago

DevGareth commented 5 years ago

Need to know how we are getting data from the server.

Will it be an api request that we send the tags to? Or the general get which is then searched for tags on frontend?

DevGareth commented 5 years ago

Also a note, I still kind of think tag should be linked to userID. Otherwise can't get their top used tags - only universally top-used tags which isn't helpful for making a graph.

robertszafa commented 5 years ago

`for tag in tags: tag_id = tag['tagID']

count this tag

        tag_count = cur.execute("SELECT * FROM Photo_Tag WHERE photoID in (SELECT photoID FROM Photo WHERE userID=%s) AND tagID=%s", (user_id, tag_id))`

Above gets the tag count for one user.

I will work on the below now. Should the 'Get Tags in desc order' be for one user or global? @DevGareth
image

DevGareth commented 5 years ago

I don't know really, depends how we want to do tags graphs.

We probably want to display to the user a list of buttons for each of their tags used in the time period. Then show the regular overall graphs specific to that tag.

So we would want local to user and over a time period: tags in descending order of usage.

And local to user and over a time period given a tag: regular data.

Tag usage could be a good graph for admin too actually.

robertszafa commented 5 years ago

Understood, will work on it now.

robertszafa commented 5 years ago

Done "over a time period: tags in descending order of usage". Below an example of the fetch call. It returns an array of tags with (tagID, name, count) in desc order.

    let basedOn = "tagUsage";
    let startDate = "28/04/2019";
    let endDate = "29/04/2019"; // exclusive
    let authToken = localStorage.getItem("authToken");
    fetch(apiMoodportfolio + '/EmotionsQuery', {
        method: "GET",
        mode: "cors",
        cache: "no-cache",
        credentials: "same-origin",
        headers: {
            "Authorization": authToken,
            "Content-Type": "application/json",
            "BasedOn": basedOn,
            "StartDate": startDate,
            "EndDate": endDate,
        },
    })
    .then((res) => res.json())
    .then(json => {
        console.log('tag emotionsquery', json)
    })
    .catch(err => console.log(err))
DevGareth commented 5 years ago

Awesome, I'm thinking a TagSelect component that does that on mount and then we just render as buttons in container. Trying to do nodeviewer atm so will get to that next

robertszafa commented 5 years ago

Done "local to user and over a time period given a tag: regular data". Below an example of the fetch call. It returns the same data as basedOnAll but basedOnTagName.

    let basedOn = "tag";
    let tagName = "tag1";
    let startDate = "28/04/2019";
    let endDate = "29/04/2019"; // exclusive
    let authToken = localStorage.getItem("authToken");
    fetch(apiMoodportfolio + '/EmotionsQuery', {
        method: "GET",
        mode: "cors",
        cache: "no-cache",
        credentials: "same-origin",
        headers: {
            "Authorization": authToken,
            "Content-Type": "application/json",
            "BasedOn": basedOn,
            "StartDate": startDate,
            "EndDate": endDate,
            "TagName": tagName,
        },
    })
    .then((res) => res.json())
    .then(json => {
        console.log('tag ', json)
    })
    .catch(err => console.log(err))
rahul-kothari commented 5 years ago

Can we close this then?