Skip to content

Commit

Permalink
improve seed db script + cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
bandinopla committed Oct 8, 2024
1 parent ecd0afb commit eaa206c
Show file tree
Hide file tree
Showing 11 changed files with 403 additions and 132 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ editor-mode.js
server/firebase-adminsdk-credential.js
sbd-rank/data.csv
.env
docs/
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ The server runs in [NodeJS](https://nodejs.org/en/) / [Express](https://expressj
- graphql -> http://weightxreps.net/api/graphql
- Schema documentation at [GraphQL Explorer](https://studio.apollographql.com/sandbox?endpoint=https%3A%2F%2Fstaging.weightxreps.net%2Fapi%2Fgraphql) That link points to the staging DB but the schema is the same.
- OAuth2 -> http://weightxreps.net/api/auth
- > Read our [api/auth documentation](OAUTH.md) if you are an app developer.
- express -> http://weightxreps.net/api


- > Read our [api/auth documentation](docs/OAUTH.md) if you are an app developer.
## :newspaper: Run dev environment
## :newspaper: Run in docker
To setup a development database on your machine use [docker](https://www.docker.com/). VS Code should detect the `.devcontainer` folder automatically. A notification will pop up, asking if you want to "Reopen in Container." Click on that option.

If you don’t see the notification, you can manually start the container by:
Expand All @@ -30,14 +27,25 @@ If you don’t see the notification, you can manually start the container by:

## No docker?
Then the specs needed to run this are:
- `Node v20.17.0`
- `mysql Ver 8.0.39` or **Ideally** `mariadb:10.6.19` with strict mode off and [`mysql_native_password`](https://dev.mysql.com/doc/refman/8.4/en/native-pluggable-authentication.html)
- Execute these queries to create the db `wxr-dev-db/sql/*.sql`
- Seed database `npm run seed-db`
- Node: `v20.17.0`
- Database: [`mariadb v10.6.19`](https://mariadb.com/kb/en/mariadb-10-6-19-release-notes/) with `@@sql_mode=""` and [`mysql_native_password`](https://dev.mysql.com/doc/refman/8.4/en/native-pluggable-authentication.html)
- Create/Edit `.env` with the DB relevant variables. (use `.env.example` as base)
- Seed database with fake data `npm run seed-db`
- *...know that the server is running on linux in production.*

---

## Seed Dev Database
You have 2 options:
1. ### Drop tables + seed
```
npm run seed-db
```
2. ### Truncate (empty) tables + seed
```
npm run truncate-db
```

## :coffee: Run local dev server

In VS Code you can go to "Run > run Dev" or "Run > Production" _it will only serve to set the NODE_ENV environment variable to development or production_
Expand All @@ -59,8 +67,13 @@ The code lives in the `./server` folder. The code that handles the GraphQL is in

- `firebase-adminsdk-credentials.js`
you will need to create & place this file inside of `server` with a [firebase account](https://console.firebase.google.com/). This is used by the "login with" widget which uses Firebase.


## Save Editor Data Format
When saving a workout, the resolver will recieve an array of `JEditorSaveRow` which is a scalar that can have many diferent interpretations...
- [resolver `saveJEditor`](server/db/resolvers/save-journal.js)
- [scalar `JEditorSaveRow`](docs/JEditorSaveRow.md)

---

## :globe_with_meridians: SBD Rank
This is the data used in the [SBD World Rank](https://weightxreps.net/sbd-stats) setion of the site.
Expand Down
52 changes: 52 additions & 0 deletions docs/JEditorSaveRow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# `scalar JEditorSaveRow`
When saving a log, you send it to the [`saveJEditor`](../server/db/resolvers/save-journal.js) mutation, where the `rows` param is an array of `JEditorSaveRow`. That type of object can come in any of these variations:

## New exercise tag
`{ newExercise:"the name of the new exercise"}`

## Bodyweight tag
`{ bw:76, lb:0 }`
- `bw` the bodyweight of the user. A `number`
- `lb` The bw comes in as the user typed it. This prop is used to know in what unit that was, being 1 = Pounds or 0=kilograms. If it is undefined the default weight unit of the current user will be used to guess it.

## Delete log tag
`{ delete:true }` Indicates that the day in which this was used should be deleted.

## Day log tag
A tag indicating what was done on a particular day...<br/>
`{ on:"YYYY-MM-DD", did:[ <DayToken> ] }`

<br/>
<br/>

# `<DayToken>` one of...

## User Tag
`{ tag:"User typed tag name", type:"TAG ID", value:"..." }`
- `tag` string typed by the user
- `type` string, a key of [tag types](https://github.com/bandinopla/weightxreps-client/blob/9c303fd7f3c825139b27b73c74e8ada4c5bd77f0/src/user-tags/data-types.js)
- `value` string, a serialized value generated by the tag itself in the frontend. See link above.

## Simple text
`{ text:"some user typed text" }`

## Exercise Block
`{ eid:number, erows:[ <Set> ] }`
- `eid` Number, id of an exercise.
- `erows` Array of `<Set>` the sets done on that execise.
<br/>
<br/>

# `<Set>` {...}
- `w` Can be an array of this object also or just this object {...}
- `v` value. Number, the weight used.
- `lb` optional `boolean` indicating if weight was typed as Pounds (lb=1) or Kilograms (lb=0)
- `usebw` optional `0 | 1` If this is `1` then `v` will be the weight added to the bodyweight and the bodyweight for the day will be used to calculate the total weight used `bw + v`
- `r` number, reps.
- `s` number, sets done.
- `c` string. User typed comment.
- `t` Optional time in milliseconds.
- `d` Optional distance done **in centimeters * 100**.
- `distance_unit` Units of the distance used one of `('cm','m','km','in','ft','yd','mi')`
- `rpe` Array of numbers or a number.
- `type` A type value of [SET_TYPES](https://github.com/bandinopla/weightxreps-client/blob/main/src/data/set-types.js) which indicates how the data of this set wil be intrpreted.
File renamed without changes.
Loading

0 comments on commit eaa206c

Please sign in to comment.