Skip to content

Commit

Permalink
Addition of API version header.
Browse files Browse the repository at this point in the history
Switch to topics_strength.
Linting fixes + rendering improvements on Results
  • Loading branch information
John Rogers committed May 3, 2024
1 parent 7502ef2 commit 947c727
Show file tree
Hide file tree
Showing 18 changed files with 688 additions and 325 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"
}
}
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 947c727

Please sign in to comment.