diff --git a/.github/actions/jest-out/action.yml b/.github/actions/jest-out/action.yml deleted file mode 100644 index e9dc614..0000000 --- a/.github/actions/jest-out/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: 'Report Audit' -description: 'report test stats for a challenge' -inputs: - challenge: - description: 'the challenge or task to report on' - required: true - lang: - description: 'the programming language in use' - required: true - server: - description: 'base API endpoint URL' - required: true - default: 'https://us-central1-buildforsdg.cloudfunctions.net/api' -runs: - using: 'node12' - main: 'index.js' \ No newline at end of file diff --git a/.github/actions/jest-out/index.js b/.github/actions/jest-out/index.js deleted file mode 100644 index db5a937..0000000 --- a/.github/actions/jest-out/index.js +++ /dev/null @@ -1,94 +0,0 @@ -const fs = require('fs'); -const axios = require('axios'); -const xml2json = require("xml2json"); -const core = require('@actions/core'); -const { context } = require('@actions/github'); - -const CHALLENGES = { - 'ch-1': 'challenge-01', - 'ch-2': 'challenge-02', - 'ch-3': 'challenge-03', - 'ch-4': 'challenge-04', - 'ch-5': 'challenge-05' -}; - -const getStatsFor = (lang, task) => { - let stats = {}; - - if (lang === 'javascript' || lang === 'python' || ['ch-4', 'ch-5'].includes(task)) { - // const payload = require(`../../../audits/${task}.json`); - const json = fs.readFileSync(`${process.cwd()}/audits/${task}.json`, 'utf8'); - const payload = JSON.parse(json); - - // HINT: how data looks - // { - // numFailedTestSuites: 1, - // numFailedTests: 1, - // numPassedTestSuites: 0, - // numPassedTests: 0, - // numPendingTestSuites: 0, - // numPendingTests: 0, - // numRuntimeErrorTestSuites: 0, - // numTodoTests: 0, - // numTotalTestSuites: 1, - // numTotalTests: 1 - // } - - stats.totalTests = payload.numTotalTests; - stats.passedTests = payload.numPassedTests; - } - - if (lang === 'php') { - const xml = fs.readFileSync(`${process.cwd()}/audits/${task}.xml`, 'utf8'); - const data = xml2json.toJson(xml, { object: true }); - - // HINT: how data looks. - // { - // testsuites: { - // testsuite: { - // name: './audits/ch-1', - // tests: '3', - // assertions: '36', - // errors: '0', - // warnings: '0', - // failures: '3', - // skipped: '0', - // time: '0.350120', - // testsuite: [Object] - // } - // } - // } - - const payload = data.testsuites.testsuite; - stats.totalTests = payload.tests; - stats.passedTests = parseInt(payload.tests, 10) - parseInt(payload.failures, 10); - } - - return stats; -}; - -const run = async () => { - try { - const task = core.getInput('challenge'); - const language = core.getInput('lang'); - const challenge = CHALLENGES[task]; - const stats = getStatsFor(language, task); - - const { repo, owner } = context.repo; - const report = { - repo, - owner, - ...stats, - language, - source: 'unit-tests', - type: challenge - }; - - const server = core.getInput('server'); - await axios.post(`${server}/entry-tests`, { report }); - } catch (error) { - core.setFailed(error.message); - } -}; - -run(); diff --git a/.github/actions/lhr-out/action.yml b/.github/actions/lhr-out/action.yml deleted file mode 100644 index 383f482..0000000 --- a/.github/actions/lhr-out/action.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: 'Report Lighthouse' -description: 'report lighthouse stats for challenge-4' -inputs: - lang: - description: 'the programming language in use' - required: true - server: - description: 'base API endpoint URL' - required: true - default: 'https://us-central1-buildforsdg.cloudfunctions.net/api' -runs: - using: 'node12' - main: 'index.js' \ No newline at end of file diff --git a/.github/actions/lhr-out/index.js b/.github/actions/lhr-out/index.js deleted file mode 100644 index b931c1f..0000000 --- a/.github/actions/lhr-out/index.js +++ /dev/null @@ -1,41 +0,0 @@ -const fs = require('fs'); -const axios = require('axios'); -const core = require('@actions/core'); -const { context } = require("@actions/github"); - -const run = async () => { - try { - const repo = context.repo.repo; - const owner = context.repo.owner; - const language = core.getInput('lang'); - - const dir = './.lighthouseci'; - const [file] = fs.readdirSync(dir).filter(f => f.startsWith('lhr-') && f.endsWith('.json')); - const lhr = JSON.parse(fs.readFileSync(`${dir}/${file}`, 'utf8')); - - const { categories } = lhr; - const stats = Object.keys(categories) - .filter(key => key !== 'pwa') - .reduce((props, key) => { - props[ key.replace('-', '') ] = categories[key].score; - return props; - }, {}); - - const report = { - repo, - owner, - language, - ...stats, - type: 'challenge-04', - source: 'lighthouse' - }; - - const server = core.getInput('server'); - await axios.post(`${server}/entry-tests`, {report}); - - } catch (error) { - core.setFailed(error.message); - } -}; - -run(); diff --git a/.github/actions/props-out/action.yml b/.github/actions/props-out/action.yml deleted file mode 100644 index bbc3420..0000000 --- a/.github/actions/props-out/action.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: 'Props Out' -description: 'expose specific properties in a .properties file' -inputs: - src: - description: 'where to look for the .properties file' - required: true - default: './' -outputs: - frontend: - description: 'URL of the hosted frontend app' - backend: - description: 'URL of the hosted backend REST API' -runs: - using: 'node12' - main: 'index.js' \ No newline at end of file diff --git a/.github/actions/props-out/index.js b/.github/actions/props-out/index.js deleted file mode 100644 index 488c6eb..0000000 --- a/.github/actions/props-out/index.js +++ /dev/null @@ -1,19 +0,0 @@ -const core = require('@actions/core'); -const propertiesReader = require('properties-reader'); - -const run = async () => { - try { - const propsLoc = core.getInput('src'); - const properties = propertiesReader(`${propsLoc}app.properties`); - const frontendURL = properties.get('frontend.url'); - const backebdAPI = properties.get('backend.rest'); - - core.setOutput('frontend', frontendURL); - core.setOutput('backend', backebdAPI); - - } catch (error) { - core.setFailed(error.message); - } -}; - -run(); diff --git a/.github/workflows/gradr.yml b/.github/workflows/gradr.yml index 7f19da5..c360d85 100644 --- a/.github/workflows/gradr.yml +++ b/.github/workflows/gradr.yml @@ -3,10 +3,10 @@ name: Gradr on: pull_request: branches: - - master + - master jobs: - lint: + lint: name: audit code style runs-on: macos-latest @@ -15,26 +15,25 @@ jobs: python-version: [3.7] steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Install Python - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Deps - run: | - python -m pip install --upgrade pip - - - name: Run Audits - run: | - pip install flake8 - # stop the build if there are Python syntax errors or undefined names - flake8 ./src/ --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 ./src/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Install Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Deps + run: | + python -m pip install --upgrade pip + + - name: Run Audits + run: | + pip install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 ./src/ --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 ./src/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics ch-1: needs: lint name: audit challenge 1 @@ -46,45 +45,44 @@ jobs: python-version: [3.7] steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Install Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Python - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Deps - run: | - pip install requests pytest pytest-json - pip install --editable . - yarn install - yarn remove jest - yarn add jest axios xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github - cd pytest-runner && yarn install && cd - - - - name: Prepare Audits - uses: actions/checkout@v2 - with: - repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-py - path: audits - - - name: Run Audits - run: | - yarn jest audits/ch-1 --json --outputFile=audits/ch-1.json --noStackTrace - - - name: Report Audits - uses: ./.github/actions/jest-out - with: - challenge: ch-1 - lang: python - if: always() - + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Deps + run: | + pip install requests pytest pytest-json + pip install --editable . + yarn install + yarn remove jest + yarn add jest axios xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github + cd pytest-runner && yarn install && cd - + + - name: Prepare Audits + uses: actions/checkout@v2 + with: + repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-py + path: audits + + - name: Run Audits + run: | + yarn jest audits/ch-1 --json --outputFile=audits/ch-1.json --noStackTrace + - name: Report Audits + uses: BuildforSDG-Cohort1-Assessment/jest-out@v1 + with: + challenge: ch-1 + lang: python + if: always() + ch-2: needs: ch-1 name: audit challenge 2 @@ -96,44 +94,43 @@ jobs: python-version: [3.7] steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Install Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Python - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Deps - run: | - pip install requests pytest pytest-json - pip install --editable . - yarn install - yarn remove jest - yarn add jest axios xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github - cd pytest-runner && yarn install && cd - - - - name: Prepare Audits - uses: actions/checkout@v2 - with: - repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-py - path: audits - - - name: Run Audits - run: | - yarn jest audits/ch-2 --json --outputFile=audits/ch-2.json --noStackTrace - - - name: Report Audits - uses: ./.github/actions/jest-out - with: - challenge: ch-2 - lang: python - if: always() + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Deps + run: | + pip install requests pytest pytest-json + pip install --editable . + yarn install + yarn remove jest + yarn add jest axios xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github + cd pytest-runner && yarn install && cd - + + - name: Prepare Audits + uses: actions/checkout@v2 + with: + repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-py + path: audits + + - name: Run Audits + run: yarn jest audits/ch-2 --json --outputFile=audits/ch-2.json --noStackTrace + + - name: Report Audits + uses: BuildforSDG-Cohort1-Assessment/jest-out@v1 + with: + challenge: ch-2 + lang: python + if: always() ch-3: needs: ch-2 @@ -146,155 +143,155 @@ jobs: python-version: [3.7] steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Install Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Python - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Deps - run: | - pip install requests pytest pytest-json - pip install --editable . - yarn install - yarn remove jest - yarn add jest axios xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github - cd pytest-runner && yarn install && cd - - - - name: Prepare Audits - uses: actions/checkout@v2 - with: - repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-py - path: audits - - - name: Run Audits - run: | - yarn jest audits/ch-3 --json --outputFile=audits/ch-3.json --noStackTrace - - - name: Report Audits - uses: ./.github/actions/jest-out - with: - challenge: ch-3 - lang: python - if: always() - + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Deps + run: | + pip install requests pytest pytest-json + pip install --editable . + yarn install + yarn remove jest + yarn add jest axios xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github + cd pytest-runner && yarn install && cd - + + - name: Prepare Audits + uses: actions/checkout@v2 + with: + repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-py + path: audits + + - name: Run Audits + run: yarn jest audits/ch-3 --json --outputFile=audits/ch-3.json --noStackTrace + + - name: Report Audits + uses: BuildforSDG-Cohort1-Assessment/jest-out@v1 + with: + challenge: ch-3 + lang: python + if: always() + lighthouse: needs: ch-3 name: audit frontend app (lighthouse) - runs-on: ubuntu-latest + runs-on: macos-latest strategy: matrix: node-version: [12.x] steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Install Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Deps - run: yarn add axios properties-reader @lhci/cli@0.3.x @actions/core @actions/github - - - name: Injest Properties - id: props - uses: ./.github/actions/props-out - - - name: Run Audits - run: npx lhci autorun --collect.url=${{ steps.props.outputs.frontend }} --config=./audits/lighthouserc.json - - - name: Report Audits - uses: ./.github/actions/lhr-out - with: - lang: javascript - if: always() - + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Deps + run: yarn add axios properties-reader @lhci/cli@0.3.x @actions/core @actions/github + + - name: Prepare Audits + uses: actions/checkout@v2 + with: + repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-js + path: audits + + - name: Injest Frontend App URL + id: props + uses: chalu/properties-io@v1 + with: + file: ./app.properties + read-from: frontend.url + + - name: Run Audits + run: npx lhci autorun --collect.url=${{ steps.props.outputs.value }} --config=./audits/lighthouserc.json + + - name: Report Audits + uses: BuildforSDG-Cohort1-Assessment/lighthouse-out@v1 + if: always() + ch-4: needs: lighthouse name: audit frontend UI - runs-on: ubuntu-latest + runs-on: macos-latest strategy: matrix: node-version: [12.x] steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Install Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Deps - run: | - yarn install - yarn add jest axios on-covid-19 properties-reader xml2json puppeteer @babel/core @babel/preset-env babel-jest @actions/core @actions/github - - name: Prepare Audits - uses: actions/checkout@v2 - with: - repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-js - path: audits - - - name: Run Audits - run: | - yarn install - npx jest audits/ch-4 --json --outputFile=audits/ch-4.json --noStackTrace - - - name: Report Audits - uses: ./.github/actions/jest-out - with: - challenge: ch-4 - lang: javascript - if: always() + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Deps + run: yarn add jest axios on-covid-19 properties-reader xml2json puppeteer @babel/core @babel/preset-env babel-jest @actions/core @actions/github + + - name: Prepare Audits + uses: actions/checkout@v2 + with: + repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-js + path: audits + + - name: Run Audits + run: npx jest --config=audits/jest.config.js audits/ch-4 --json --outputFile=audits/ch-4.json --noStackTrace + + - name: Report Audits + uses: BuildforSDG-Cohort1-Assessment/jest-out@v1 + with: + challenge: ch-4 + lang: javascript + if: always() ch-5: needs: ch-3 name: audit backend API - runs-on: ubuntu-latest + runs-on: macos-latest strategy: matrix: node-version: [12.x] steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Install Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Deps - run: | - yarn install - yarn add jest axios on-covid-19 properties-reader xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github - - name: Prepare Audits - uses: actions/checkout@v2 - with: - repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-js - path: audits - - - name: Run Audits - run: | - yarn install - npx jest audits/ch-5 --json --outputFile=audits/ch-5.json --noStackTrace - - - name: Report Audits - uses: ./.github/actions/jest-out - with: - challenge: ch-5 - lang: javascript - if: always() + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Deps + run: yarn add jest axios on-covid-19 properties-reader xml2json @babel/core @babel/preset-env babel-jest @actions/core @actions/github + + - name: Prepare Audits + uses: actions/checkout@v2 + with: + repository: BuildforSDG-Cohort1-Assessment/covid-19-estimator-audits-js + path: audits + + - name: Run Audits + run: npx jest --config=audits/jest.config.js audits/ch-5 --json --outputFile=audits/ch-5.json --noStackTrace + + - name: Report Audits + uses: BuildforSDG-Cohort1-Assessment/jest-out@v1 + with: + challenge: ch-5 + lang: javascript + if: always() diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..b5846df --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] + +[requires] +python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..e42812c --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,20 @@ +{ + "_meta": { + "hash": { + "sha256": "7f7606f08e0544d8d012ef4d097dabdd6df6843a28793eb6551245d4b2db4242" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.8" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/src/estimator.py b/src/estimator.py index f4517e6..bb354c3 100644 --- a/src/estimator.py +++ b/src/estimator.py @@ -1,2 +1,54 @@ + + + + def estimator(data): - return data + input_data = { + 'region': { + 'name': "Africa", + 'avgAge': 19.7, + 'avgDailyIncomeInUSD': 5, + 'avgDailyIncomePopulation': 0.71 + }, + 'periodType': "days", + 'timeToElapse': 58, + 'reportedCases': 674, + 'population': 66622705, + 'totalHospitalBeds': 1380614 +} + + def convert_2_days(): + if input_data['periodType'] == 'days': + converted_days = input_data['timeToElapse'] + + elif input_data['periodType'] == 'weeks': + converted_days = input_data['timeToElapse'] * 7 + + elif input_data['periodType'] == 'weeks': + converted_days = input_data['timeToElapse'] * 30 + + return converted_days + + + return { + 'data': input_data, + + 'impact': { + 'currentlyInfected': input_data['reportedCases'] * 10, + 'infectionsByRequestedTime': (input_data['reportedCases'] * 10) * (2 ** ( convert_2_days() / 3 )) + }, + + 'severeImpact': { + 'currentlyInfected': input_data['reportedCases'] * 50, + 'infectionsByRequestedTime': (input_data['reportedCases'] * 10) * (2 ** ( convert_2_days() / 3)) + } + + } + + +''' + +a = 34 +b = 34 % 3 +print(b) +''' \ No newline at end of file