Skip to content

Commit

Permalink
Merge pull request #4 from odu-emse/ALMP-591
Browse files Browse the repository at this point in the history
Completed recommendation logic for API access
  • Loading branch information
chef-danny-d authored Mar 2, 2023
2 parents e803302 + 398b903 commit 6589a03
Show file tree
Hide file tree
Showing 29 changed files with 973 additions and 382 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and Deploy Docs

on:
push:
branches: [ 'dev', 'master', 'ALMP-**' ]

jobs:
docs:
runs-on: ubuntu-latest
name: Create Docs
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9.13'
cache: 'pip' # caching pip dependencies
- name: Install dependencies
run: pip install -r requirements.txt
- name: Set env variables
run: |
echo "DATABASE_URL=${{secrets.DATABASE_URL}}" > .env
echo "DIRECT_URL=${{secrets.DIRECT_URL}}" > .env
- name: Generate Prisma types
run: prisma generate
- name: Generate docs
run: pdoc --html --output-dir docs --force .
- name: Deploy docs
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs/emse-mms
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
input/
.DS_Store
/.env
__pycache__/
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM python:3.9.13
FROM python:3.9.13 as base

RUN apt-get update
RUN apt-get -y update

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
RUN pip install --no-cache-dir -r requirements.txt

CMD [ "python", "./app.py" ]
COPY . .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ docker-compose up -d
#### Get module recommendations for a user

```http
GET /recommend/${userID}
GET /recommend/${userID}
```

| Parameter | Type | Description |
Expand Down
13 changes: 8 additions & 5 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from fastapi import FastAPI

from app import getUserProfile
import json
from recommend import Recommender, Recs

app = FastAPI()


@app.get("/recommend/")
async def read_item(userID: str):
account = await getUserProfile(userID)
print(account)
return {"user": account}
rec = Recs()
res = await rec.run()

cleaned_data = json.loads(res)

return {"user": userID, "data": cleaned_data[0:50]}
54 changes: 3 additions & 51 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,23 @@
from pandas import DataFrame
import asyncio
from prisma import Prisma

from utils.db import testConnection
from utils.response import getModuleFromID
from utils.seed import getModuleFeedback, Seeder, Skipper
from utils.helper import convertReviewsFromDbToDf
from utils.seed import Seeder, Skipper


async def main() -> None:
print('Starting application...')
testConnection()
# await seedUserDB()
# seedModuleModel()
# await seedPlanOfStudyDB()
# await seedEnrollmentDB()

db = Seeder(
skip=[Skipper.all],
cleanup=[Skipper.all],
iterations=100
iterations=100,
)

await db.seedAll()
await db.cleanupAll()
await getUserProfile(ID="63da9e40020a625cc55f64c5")
# targetID = await db.createTargetUser()

exit(0)
# seedModuleModel()
# seedDbFeedback()


def getReviews(userID):
# read data
mod_data = getModuleFeedback()
df = convertReviewsFromDbToDf(mod_data['module'], userID)

# print(df)
# print(df.groupby(['userID', 'moduleID']).sum().sort_values('rating', ascending=False).head())
# print(df.groupby('moduleID')['rating'].sum().sort_values(ascending=False).head())

# get highest rated modules
top_mods: DataFrame = df.groupby('moduleID')['rating'].sum().sort_values(ascending=False)

# run response for each row of the highest rated modules
print(top_mods)
res_top_mods = top_mods.reset_index()
res_top_mods.apply(lambda row: getModuleFromID(row), axis=1)


async def getUserProfile(ID):
print('Fetching user data...')
# get user from ID
# find enrolled modules
# remove modules that already enrolled in
# get feedback for each module
# get similarity matrix
# get recommendations
# return recommendations
prisma = Prisma()
await prisma.connect()
account = await prisma.user.find_unique(
where={
'id': ID
}
)
print(account)


if __name__ == '__main__':
Expand Down
47 changes: 15 additions & 32 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
version: "3.8"

services:
# db:
# image: mongo:latest
# container_name: db
# environment:
# MONGO_INITDB_ROOT_USERNAME: root
# MONGO_INITDB_ROOT_PASSWORD: example
# ports:
# - "27017:27017"
# - '28017:28017'
# networks:
# - mmsNetwork
# command: >
# bash -c "mongod --replSet rs0 --bind_ip localhost,db"
#
# mongo-express:
# depends_on:
# - db
# image: mongo-express
# ports:
# - "8081:8081"
# environment:
# ME_CONFIG_MONGODB_ADMINUSERNAME: root
# ME_CONFIG_MONGODB_ADMINPASSWORD: example
# ME_CONFIG_MONGODB_URL: mongodb://root:example@db:27017/
# ME_CONFIG_MONGODB_ENABLE_ADMIN: true
# networks:
# - mmsNetwork

app:
depends_on:
- db
container_name: app
build:
context: .
dockerfile: Dockerfile

command: >
bash -c "prisma generate && python app.py"
networks:
- mmsNetwork
api:
container_name: api
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
command: >
bash -c "prisma generate && python3 -m uvicorn api:app --reload --host 0.0.0.0"
networks:
- mmsNetwork
client:
depends_on:
- redis
Expand All @@ -46,7 +30,6 @@ services:
- .env
ports:
- "4000:4000"
- "5555:5555"
command: >
bash -c "yarn && yarn generate && yarn dev"
networks:
Expand Down
File renamed without changes.
16 changes: 9 additions & 7 deletions html/emse-mms/app.html → docs/emse-mms/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ <h1 class="title">Module <code>emse-mms.app</code></h1>

db = Seeder(
skip=[Skipper.all],
cleanup=[Skipper.all]
cleanup=[Skipper.all],
iterations=100
)

await db.seedAll()
await db.cleanupAll()
await getUserProfile(ID=&#34;63da9e40020a625cc55f64c5&#34;)

exit(0)
# seedModuleModel()
# seedDbFeedback()
# getReviews(userID=&#34;63da9e40020a625cc55f64c5&#34;)


def getReviews(userID):
Expand Down Expand Up @@ -92,7 +93,7 @@ <h1 class="title">Module <code>emse-mms.app</code></h1>
&#39;id&#39;: ID
}
)
return account.dict()
print(account)


if __name__ == &#39;__main__&#39;:
Expand Down Expand Up @@ -158,7 +159,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
&#39;id&#39;: ID
}
)
return account.dict()</code></pre>
print(account)</code></pre>
</details>
</dd>
<dt id="emse-mms.app.main"><code class="name flex">
Expand All @@ -180,16 +181,17 @@ <h2 class="section-title" id="header-functions">Functions</h2>

db = Seeder(
skip=[Skipper.all],
cleanup=[Skipper.all]
cleanup=[Skipper.all],
iterations=100
)

await db.seedAll()
await db.cleanupAll()
await getUserProfile(ID=&#34;63da9e40020a625cc55f64c5&#34;)

exit(0)
# seedModuleModel()
# seedDbFeedback()
# getReviews(userID=&#34;63da9e40020a625cc55f64c5&#34;)</code></pre>
# seedDbFeedback()</code></pre>
</details>
</dd>
</dl>
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions html/emse-mms/index.html → docs/emse-mms/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="emse-mms.endpoints" href="endpoints/index.html">emse-mms.endpoints</a></code></dt>
<dt><code class="name"><a title="emse-mms.recommend" href="recommend.html">emse-mms.recommend</a></code></dt>
<dd>
<div class="desc"></div>
</dd>
Expand Down Expand Up @@ -66,7 +66,7 @@ <h1>Index</h1>
<li><code><a title="emse-mms.api" href="api.html">emse-mms.api</a></code></li>
<li><code><a title="emse-mms.app" href="app.html">emse-mms.app</a></code></li>
<li><code><a title="emse-mms.db" href="db/index.html">emse-mms.db</a></code></li>
<li><code><a title="emse-mms.endpoints" href="endpoints/index.html">emse-mms.endpoints</a></code></li>
<li><code><a title="emse-mms.recommend" href="recommend.html">emse-mms.recommend</a></code></li>
<li><code><a title="emse-mms.utils" href="utils/index.html">emse-mms.utils</a></code></li>
</ul>
</li>
Expand Down
Loading

0 comments on commit 6589a03

Please sign in to comment.