Skip to content

Commit

Permalink
Merge pull request #19 from harmonydata/staging
Browse files Browse the repository at this point in the history
Releasing Staging version
  • Loading branch information
ronnyTodgers authored May 13, 2024
2 parents cba3ad5 + e06870f commit ff3998f
Show file tree
Hide file tree
Showing 21 changed files with 704 additions and 332 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ REACT_APP_API_URL=https://api.harmonydata.ac.uk
REACT_APP_API_EXAMPLES=$REACT_APP_API_URL/text/examples
REACT_APP_API_PARSE=$REACT_APP_API_URL/text/parse
REACT_APP_API_MATCH=$REACT_APP_API_URL/text/match
REACT_APP_API_VERSION=$REACT_APP_API_URL/info/version
REACT_APP_ABSOLUTE_URL_PREFIX=https://harmonydata.github.io
1 change: 1 addition & 0 deletions TEST .env.development → .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ REACT_APP_API_URL=https://harmonystagingtmp.azurewebsites.net/
REACT_APP_API_EXAMPLES=$REACT_APP_API_URL/text/examples
REACT_APP_API_PARSE=$REACT_APP_API_URL/text/parse
REACT_APP_API_MATCH=$REACT_APP_API_URL/text/match
REACT_APP_API_VERSION=$REACT_APP_API_URL/info/version
REACT_APP_ABSOLUTE_URL_PREFIX=https://harmonydata.github.io
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "harmony-6bd51"
}
}
13 changes: 8 additions & 5 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
# build and deploy release branch to GH pages

name: Build and Deploy to GH pages
name: Build and Deploy Release branch to GH pages


# after the next release this should be updated to true
env:
CI: false

on:
push:
branches: ["master"]
branches: ["release"]
pull_request:
types: closed
branches: ["master"]
branches: ["release"]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: "release"
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
package-lock.json
/wireframes
package-lock.json
functions/venv
functions/__pycache__
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ You can contact Harmony team at https://harmonydata.ac.uk/, Thomas Wood at http:

## Deployment

This app is deployed using Github actions when there is a push to `main` branch. The script to do this is under folder `.github`.
Commits / pull requests to the master or staging branches will trigger an automatic build on netlifiy - temporay build URLS will be displayed in pull requests and please manually confirm your commits are working as intended.

The staging branch is always available at https://harmony-staging.netlify.app/

This app is deployed to the main website using Github actions when there is a push to `releases` branch - this is a protected branch. The script to do this is under folder `.github`.

Ulster University is managing the domain `harmonydata.ac.uk` which is configured to point to the IPs of the Github Pages deployment.

For the staging app we are using a Netlify build with build hooks - please contact Thomas Wood/John Rogers for details.


# How to contribute

Expand Down
18 changes: 18 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"venv",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
]
}
4 changes: 4 additions & 0 deletions firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
22 changes: 22 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
rules_version = '2';

service cloud.firestore {
match /databases/{database}/documents {
match /harmonisations/{document} {
// allow read access to own or public
allow read: if resource.data.public == true || resource.data.uid == request.auth.uid;
// write access to own
allow write: if resource.data.uid == request.auth.uid;
// create access to any logged in
allow create: if request.auth != null;
}
match /mismatches/{document} {
// allow create access to public
allow create, write: if true ;
}
match /ratings/{document} {
// allow create access to public
allow create, write: if true ;
}
}
}
2 changes: 2 additions & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv
__pycache__
44 changes: 44 additions & 0 deletions functions/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Welcome to Cloud Functions for Firebase for Python!
# To get started, simply uncomment the below code or create your own.
# Deploy with `firebase deploy`

from firebase_functions import https_fn
from firebase_admin import initialize_app
from firebase_admin import firestore
import json
import datetime

app = initialize_app()
db = firestore.client()

# Define a custom function to serialize datetime objects
def serialize_datetime(obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat()
raise TypeError("Type not serializable")

@https_fn.on_request(region="europe-west1")
def api(req: https_fn.Request) -> https_fn.Response:
data = []
match req.path:
case "/mismatches":
docs = db.collection("mismatches").stream()
for doc in docs:
d = doc.to_dict()
d["fbid"] = doc.id
data.append(d)
case "/harmonisations":
docs = db.collection("harmonisations").stream()
for doc in docs:
d = doc.to_dict()
d["fbid"] = doc.id
data.append(d)
case "/ratings":
docs = db.collection("ratings").stream()
for doc in docs:
d = doc.to_dict()
d["fbid"] = doc.id
data.append(d)
case _ :
data.append("No such end point " + req.path )
return https_fn.Response(json.dumps(data, default=serialize_datetime), mimetype="application/json")
1 change: 1 addition & 0 deletions functions/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
firebase_functions~=0.1.0
44 changes: 32 additions & 12 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import logoWithText from "../img/Logo-04-min.svg";
import ResultsOptions from "./ResultsOptions";
import { deepmerge } from "@mui/utils";
import { ColorModeContext } from "../contexts/ColorModeContext";
import postData from "../utilities/postData";
import { useData } from "../contexts/DataContext";
import { utils as XLSXutils, writeFile as XLSXwriteFile } from "xlsx";
import ReactGA from "react-ga4";
Expand All @@ -47,7 +46,7 @@ function App() {
});
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
const [mode, setMode] = useState();
const { storeHarmonisation, reportRating } = useData();
const { storeHarmonisation, reportRating, exampleInstruments } = useData();
const [ratingValue, setRatingValue] = useState();
const [computedMatches, setComputedMatches] = useState();
const [fileInfos, setFileInfos] = useState();
Expand Down Expand Up @@ -88,15 +87,15 @@ function App() {
ReactGA.initialize("G-S79J6E39ZP");
console.log("GA enabled");
}
postData(process.env.REACT_APP_API_EXAMPLES)
exampleInstruments()
.then((data) => {
setExistingInstruments(data);
console.log(data);
})
.catch((e) => {
console.log(e);
});
}, []);
}, [exampleInstruments]);

const colorMode = useMemo(
() => ({
Expand Down Expand Up @@ -202,11 +201,14 @@ function App() {
instrument1: q.instrument.name,
question1_no: q.question_no,
question1_text: q.question_text,
question1_topics: q.topics_auto.toString(),
question1_topics:
Array.isArray(q.topics_strengths) && q.topics_strengths.join(", "),
instrument2: mq.instrument.name,
question2_no: mq.question_no,
question2_text: mq.question_text,
question2_topics: mq.topics_auto.toString(),
question2_topics:
Array.isArray(mq.topics_strengths) &&
mq.topics_strengths.join(", "),
match: cm.match,
});
return a;
Expand Down Expand Up @@ -328,16 +330,33 @@ function App() {
Harmonise questionnaire items
</h1>
<p>
Harmony is an AI tool which can read questionnaires and find questions with similar meanings, such as{" "}
Harmony is an AI tool which can read questionnaires and
find questions with similar meanings, such as{" "}
<i>anxiety</i> vs <i>I feel anxious</i>.
</p>
<p>
Psychologists sometimes need to combine survey results, especially when surveys
have been run by different organisations or in different
countries.
Psychologists sometimes need to combine survey results,
especially when surveys have been run by different
organisations or in different countries.
</p>
<p>
Try two example PDFs: <a target="gad7-pdf" style={{ color: "white" }} href="https://adaa.org/sites/default/files/GAD-7_Anxiety-updated_0.pdf">GAD-7 PDF</a> vs <a target="phq-pdf" style={{ color: "white" }} href="https://www.apa.org/depression-guideline/patient-health-questionnaire.pdf">PHQ-9 PDF</a>.
Try two example PDFs:{" "}
<a
target="gad7-pdf"
style={{ color: "white" }}
href="https://adaa.org/sites/default/files/GAD-7_Anxiety-updated_0.pdf"
>
GAD-7 PDF
</a>{" "}
vs{" "}
<a
target="phq-pdf"
style={{ color: "white" }}
href="https://www.apa.org/depression-guideline/patient-health-questionnaire.pdf"
>
PHQ-9 PDF
</a>
.
</p>
<p>
<a
Expand Down Expand Up @@ -406,7 +425,8 @@ function App() {
setResultsOptions={setResultsOptions}
resultsOptions={resultsOptions}
toaster={toast}
reportComputedMatches={setComputedMatches}
computedMatches={computedMatches}
setComputedMatches={setComputedMatches}
ReactGA={ReactGA}
/>
</Route>
Expand Down
Loading

0 comments on commit ff3998f

Please sign in to comment.