-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e20b70
commit 371fff2
Showing
14 changed files
with
289 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
cake-game/src/components/classifier-table-row/ClassifierTableRow.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.image { | ||
width: 50px; | ||
height: auto; | ||
} | ||
|
||
.classification { | ||
font-weight: normal; | ||
} | ||
|
||
tr { | ||
padding: 0.5rem 3rem; | ||
} | ||
|
||
.row { | ||
background-color: var(--qwik-dark-background); | ||
} | ||
|
||
.alternative-row { | ||
background-color: var(--qwik-alt-background); | ||
} |
37 changes: 37 additions & 0 deletions
37
cake-game/src/components/classifier-table-row/ClassifierTableRow.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import "./ClassifierTableRow.css"; | ||
|
||
function ClassifierTableRow(props) { | ||
|
||
function formatClassificationCollections(predictions, attributeName) { | ||
if (!predictions || predictions.length === 0) { | ||
return 'N/A'; | ||
} | ||
|
||
return predictions[0][attributeName]; | ||
} | ||
|
||
function formatClassificationString(classifier) { | ||
if (!classifier) { | ||
return 'N/A'; | ||
} | ||
|
||
return classifier; | ||
} | ||
|
||
return ( | ||
<> | ||
<tr className={`${ props.rowNumber % 2 === 0 ? 'alternative-row' : 'row'}`}> | ||
<th> | ||
<img className="image" alt="Random image" src={props.result.image_url} /> | ||
</th> | ||
<th className="classification">{ props.result.user_category }</th> | ||
<th className="classification">{ formatClassificationCollections(props.result.models.mobilenet_classifier, 'className') }</th> | ||
<th className="classification">{ formatClassificationCollections(props.result.models?.coco_ssd_predictions, 'class') }</th> | ||
<th className="classification">{ formatClassificationString(props.result.models?.my_transfer_model_classifier?.category) }</th> | ||
<th className="classification">{ formatClassificationString(props.result.models?.my_model_classifier.category) }</th> | ||
</tr> | ||
</> | ||
); | ||
} | ||
|
||
export default ClassifierTableRow; |
9 changes: 9 additions & 0 deletions
9
cake-game/src/components/classifier-table-row/ClassifierTableRow.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { test, expect } from '@playwright/experimental-ct-react'; | ||
import ClassifierTableRow from './ClassifierTableRow'; | ||
|
||
test.use({ viewport: { width: 500, height: 500 } }); | ||
|
||
test('should render', async ({ mount }) => { | ||
const component = await mount(<ClassifierTableRow />); | ||
expect(component).toBeDefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getGameResults } from "../util/elasticsearch"; | ||
import { convertRequest, generateResponse } from "../util/helper"; | ||
|
||
/** | ||
* Get a random image | ||
* Note: Netlify deploys this function at the endpoint /.netlify/functions/image | ||
* @param {*} event | ||
* @param {*} context | ||
* @returns | ||
*/ | ||
export async function handler(event, context) { | ||
const gameMetadata = convertRequest(event.body); | ||
|
||
try { | ||
const response = await getGameResults(gameMetadata); | ||
const results = response.hits.hits.flatMap((document) => { | ||
return document._source; | ||
}); | ||
|
||
return generateResponse(200, results); | ||
} catch (e) { | ||
console.log(e); | ||
|
||
return generateResponse(500, e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
section { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 2rem; | ||
|
||
margin: auto; | ||
} | ||
|
||
table { | ||
width: 95%; | ||
|
||
/*padding: 0.5rem 2rem;*/ | ||
|
||
border: 1px solid; | ||
border-color: var(--qwik-dark-purple); | ||
} | ||
|
||
.header-row { | ||
background-color: var(--qwik-dark-background); | ||
color: var(--qwik-dark-text); | ||
font-size: large; | ||
|
||
height: 5rem; | ||
} | ||
|
||
th { | ||
text-wrap: wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useEffect, useState } from "react"; //TO DO should I use useMemo to get results and classifications | ||
import { useNavigate, useSearchParams } from "react-router-dom"; | ||
|
||
import axios from "axios"; | ||
|
||
import "./End.css"; | ||
import ClassifierTableRow from "../../components/classifier-table-row/ClassifierTableRow"; | ||
import StartButton from "../../components/start-button/StartButton"; | ||
|
||
function End() { | ||
const navigate = useNavigate(); | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
const [username, setUsername] = useState(); | ||
const [gameId, setGameId] = useState(); | ||
|
||
const [results, setResults] = useState(); | ||
|
||
useEffect(() => { | ||
if (searchParams && !gameId) { | ||
const user = searchParams.get("username"); | ||
const game = searchParams.get("game_id"); | ||
|
||
setUsername(user); | ||
setGameId(game); | ||
|
||
getGameResults(user, game); | ||
} | ||
}, [username, gameId]); | ||
|
||
async function getGameResults(user, game) { | ||
const gameMetadata = { username: user, game_id: game }; | ||
|
||
try { | ||
const response = await axios.post( | ||
".netlify/functions/game_results", | ||
gameMetadata | ||
); | ||
|
||
if (response.status !== 200) { | ||
throw new Error("Unable to get game results"); | ||
} | ||
|
||
const gameResults = response.data; | ||
setResults(gameResults); | ||
} catch (error) { | ||
console.log("Unable to get game results"); | ||
setResults([]); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<section className="section bright"> | ||
<h1> | ||
Were they <span className="highlight">(F)ake</span>?! | ||
</h1> | ||
|
||
<p> | ||
Did you find the cake? Check out how you fared against our models | ||
below. | ||
</p> | ||
|
||
{results && results.length > 0 ? ( | ||
<table> | ||
<thead className="table-header"> | ||
<tr className="header-row"> | ||
<th>Image</th> | ||
<th>You</th> | ||
<th>MobileNet</th> | ||
<th>COCO-SSD</th> | ||
<th>MobileNet Transfer Classifier</th> | ||
<th>Carly Model</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{results.map((result, index) => { | ||
return <ClassifierTableRow key={index} rowNumber={index} result={result} />; | ||
})} | ||
</tbody> | ||
</table> | ||
) : ( | ||
<p>No results available!</p> | ||
)} | ||
<p>Want to try again?</p> | ||
<StartButton /> | ||
</section> | ||
</> | ||
); | ||
} | ||
|
||
export default End; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { test, expect } from '@playwright/experimental-ct-react'; | ||
import End from './End'; | ||
|
||
test.use({ viewport: { width: 500, height: 500 } }); | ||
|
||
test('should work', async ({ mount }) => { | ||
const component = await mount(<End />); | ||
expect(component).toBeDefined(); | ||
//await expect(component).toContainText('Is it (F)ake?!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.