Skip to content

Commit

Permalink
Merge pull request #13 from hnwyllmm/main
Browse files Browse the repository at this point in the history
oceanbase devcon 2024 challege
  • Loading branch information
hnwyllmm authored Apr 16, 2024
2 parents 7749c24 + 23f3301 commit 7b7d86a
Show file tree
Hide file tree
Showing 16 changed files with 3,109 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/challenge-2024.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Sample workflow for building and deploying a mdBook site to GitHub Pages
#
# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
#
name: Deploy Challenge 2024

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
env:
MDBOOK_VERSION: 0.4.36
steps:
- uses: actions/checkout@v4

- name: Install node and yarn
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y nodejs npm yarn
- name: Build with yarn
run: |
yarn
yarn build
working-directory: 2024/challenge
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 2024/challenge/dist

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 4 additions & 0 deletions 2024/challenge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# OceanBase 知识挑战

## 安装
安装的软件和构建的方法请参考 .github/workflows/challenge-2024.yml 文件。
13 changes: 13 additions & 0 deletions 2024/challenge/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/oceanbase.ico.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OceanBase 知识挑战</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions 2024/challenge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "ob-exam",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build --base=/devcon/",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"antd": "^5.16.1",
"bulma": "^1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}
Binary file added 2024/challenge/public/oceanbase.ico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions 2024/challenge/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
159 changes: 159 additions & 0 deletions 2024/challenge/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import 'bulma/css/bulma.css'
import { Form, Checkbox, Radio, Space, Typography, Button, Input } from 'antd'
import React from 'react'
import questionsData from './questions.json'

enum QuestionType {
MultipleChoice = 'MultipleChoice',
SingleChoice = 'SingleChoice',
}

type QuestionAnswer = {
content: string
isCorrect?: boolean
}

type Question = {
id: string
title: string
description?: string
type: string
answers: QuestionAnswer[]
}

const questions: Question[] = questionsData.questionsData

const correctMapping: Record<string, string[]> = Object.fromEntries(questions.map((q) => [q.id, q.answers.filter((a) => a.isCorrect).map((a) => a.content)]))
const questionMapping: Record<string, Question> = Object.fromEntries(questions.map((q) => [q.id, q]))


function App() {
const [form] = Form.useForm()
const [formGithubId] = Form.useForm()
const [wrongAnswers, setWrongAnswers] = React.useState<string[]>([])
const [score, setScore] = React.useState<number>(-1)
const [submitted, setSubmitted] = React.useState<boolean>(false)
const [githubId, setGithubId] = React.useState<string>("")
for (const q of questions) {
q.answers = q.answers.sort(() => Math.random() - 0.5)
}
return (
<>
<section className="hero is-info">
<div className="hero-body">
<p className="title" style={{ marginBottom: 8 }}>OceanBase 知识挑战</p>
<p className="subtitle">请选择你认为正确的答案,完成答题后点击【提交】</p>
</div>

</section>

<div style={{
margin: 'auto',
paddingTop: '60px',
paddingBottom: '60px',
paddingLeft: '2%',
paddingRight: '2%',
}}>
{!submitted && (<Form form={form} layout={'vertical'} size={'large'}>
{questions.map((q, idx) =>

<div style={{padding:25}} className="box" key={q.id}>
{
//(<Typography.Text strong style={{paddingBottom:16}}>{`${idx + 1}. ${q.title}`}</Typography.Text>)
<div style={{marginBottom: 16}}><b>{`${idx + 1}. ${q.title}`}</b></div>
}
<Form.Item
name={q.id}
rules={[{ required: true, message: '请回答该问题' }]}
>

{
q.type === QuestionType.SingleChoice ?
(<Radio.Group>
<Space direction={'vertical'}>
{q.answers.map((a) => <Radio key={a.content} value={a.content}>{a.content}</Radio>)}
</Space>
</Radio.Group>) :
(<Checkbox.Group>
<Space direction={'vertical'}>
{q.answers.map((a) => <Checkbox key={a.content} value={a.content}>{a.content}</Checkbox>)}
</Space>
</Checkbox.Group>)
}
</Form.Item>
</div>
)}
</Form>
)}
{!submitted && (<Form form={formGithubId} layout={'vertical'}>
<div style={{paddingTop:25}} >
<Form.Item name="githubIdFormValue" rules={[{ required: true, message: '请输入GitHub ID' }]}>
<Input key="githubIdInputValue" value="githubIdInputValueName" placeholder="请输入你的github id" style={{ width: 200 }} />
</Form.Item>
</div>
</Form>
)}
{ !submitted && (
<Space style={{ marginTop: 24 }}>

<Button type="primary" onClick={async () => {
const githubIdValue = await formGithubId.validateFields()
setGithubId(githubIdValue.githubIdFormValue)

const values = await form.validateFields()
let score = 0
const wrongAnswers: string[] = []
for (const [id, answers] of Object.entries(values)) {
const correct = correctMapping[id]
if (typeof answers === 'string') {
if (correct.includes(answers)) {
score += 5
} else {
wrongAnswers.push(id)
}
} else if (Array.isArray(answers)) {
if (correct.every((c) => answers.includes(c)) && correct.length === answers.length) {
score += 5
} else {
wrongAnswers.push(id)
}
}
}
setWrongAnswers(wrongAnswers)
setScore(score)
setSubmitted(true)
console.log("score", score)
// message.info(`你的得分是 ${score}`)
}}>提交</Button>
</Space>
)}
{score >= 0 && (
<div style={{ marginTop: 32 }}>
<Typography.Title level={4}>{githubId} 你的得分是 {score}</Typography.Title>
</div>
)}
{wrongAnswers.length > 0 && (
<div style={{ marginTop: 32 }}>
<Typography.Title level={4}>错误题目</Typography.Title>
<ul>
{wrongAnswers.map((id) => (
<li key={id} style={{marginTop: 16}}>
<Typography.Title level={5}>{`${id}. ${questionMapping[id].title}`}</Typography.Title>
<ul>
{correctMapping[id].map((c) => (
<li key={c}>
<Typography.Text type={'success'}>{c}</Typography.Text>
</li>
))}
</ul>
</li>
))}
</ul>
</div>
)}
</div>
</>
)
}

export default App
1 change: 1 addition & 0 deletions 2024/challenge/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions 2024/challenge/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
/* display: flex; */
/* place-items: center; */
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
10 changes: 10 additions & 0 deletions 2024/challenge/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
Loading

0 comments on commit 7b7d86a

Please sign in to comment.