Code Monkey home page Code Monkey logo

moadata-wanted-a's Introduction

원티드 프리온보딩 백엔드 프로젝트 4



목차



팀구성


프로젝트 개요

  • DAG개념이 포함된 json데이터의 REST API개발 및 csv 데이터처리

✍️ 프로젝트 구조

❯ tree -N -L 2 -I "venv|.github|__pycache__"                                                                                                  ─╯
.
├── README.md
├── app.py
├── data
│   ├── a.csv
│   └── b.csv
├── database
│   ├── db.py
│   └── model.py
├── requirements.txt
├── resources
│   ├── errors.py
│   ├── routes.py
│   └── views.py
├── test.py
└── utils
    └── executors.py

4 directories, 12 files

🛠 기술스택



프로젝트 진행과정

  • Notion과 Git branch를 연동하여 작업 진행 (Notion 링크)

image

image


✎ DFD

Screen Shot 2022-05-17 at 14 30 07


Job Save

  • Tag: 1.0.0 : Client는 Job 정보를 Server에게 전송
  • Tag: 1.1.0 : Server는 받은 정보를 job.json(mongodb)에 저장

Job Delete

  • Tag: 2.0.0 : Client는 특정 Job정보를 삭제하기 위해 job id를 서버로 전송
  • Tag: 2.1.0 : Server는 받아온 job id에 해당하는 job 정보를 삭제

Job Modify

  • Tag: 3.0.0 : Client는 특정 Job정보를 수정하기 위해 job id를 서버로 전송
  • Tag: 3.1.0 : Server는 받아온 job id에 해당하는 job 정보를 수정

Job Run

  • Tag: 4.0.0 : Client는 특정 Job을 실행하기 위해 job id를 서버로 전송
  • Tag: 4.1.0 : Server는 받아온 job id에 해당하는 job list를 얻음
    • Tag: 4.1.1 : read task를 수행을 위해 특정 file에 접근
    • Tag: 4.1.2 : file의 값을 얻어 pandas의 DataFrame으로 전달
  • Tag: 4.2.0 : 특정 column_name을 제외하여 DataFrame으로 전달
  • Tag: 4.3.0 : 전달받은 데이터를 새로운 file로 저장 및 Client에게 전달


📝 API 명세서

Job 실행 : api/v1/jobs/<int:pk>/run

  • GET /api/v1/jobs/1/run

    • 요청 Body

      None
      
    • server 응답

      "job_id=1 run task Success"
    • 결과

      • task_list의 작업(예를들면 read -> drop -> write)이 진행된다.
      • a.csv파일 수정의 결과값인 b.csv파일이 생성된다.
    • 존재하지 않는 id값으로 요청에 대한 server 응답

      {
          "message": "Job with given id doesn't exists",
          "status": 400
      }

Job 저장 및 리스트 : api/v1/jobs

  • POST /api/v1/jobs

    • 요청 Body

      {
        "job_id" : 1,
          "job_name" : "Job1",
          "task_list" : {
              "read" : ["drop"], 
              "drop" : ["write"], 
              "write" : []
          },
          "property" : {
              "read": {
                  "task_name": "read", 
                  "filename" : "data/a.csv", 
                  "sep" :","
              }, 
              "drop" : {
                  "task_name": "drop", 
                  "column_name": "date"
              }, 
              "write" : {
                  "task_name": "write", 
                  "filename" : "data/b.csv", 
                  "sep": ","
              }
          }
      }
    • server 응답

      "job_id=1 created OK"

  • GET /api/v1/jobs

    • 요청 Body

      None
      
    • Server 응답

      [
        {
          "_id": {
            "$oid": "6283915c6e955720caac4535"
          },
          "job_id": 1,
          "job_name": "Job1",
          "task_list": {
            "read": [
              "drop"
            ],
            "drop": [
              "write"
            ],
            "write": []
          },
          "property": {
            "read": {
              "task_name": "read",
              "filename": "data/a.csv",
              "sep": ","
            },
            "drop": {
              "task_name": "drop",
              "column_name": "date"
            },
            "write": {
              "task_name": "write",
              "filename": "data/b.csv",
              "sep": ","
            }
          }
        },
        
        ,
        (중간생략)
        ,
      ]

Job 수정, 삭제 및 상세보기 api/v1/jobs/<int:pk>

  • DELETE /api/v1/jobs/1

    • 요청 Body

      None
      
    • Server 응답

      "job_id=1 deleted OK"
    • 삭제 후 재요청에 대한 Server 응답

      {
          "message": "Deleting Job added by other is forbidden",
          "status": 403
      }

  • PUT /api/v1/jobs/1

    • 요청 Body

      {
          "job_name" : "Job1",
          "task_list" : {
              "read" : ["drop"], 
              "drop" : ["write"], 
              "write" : []
          },
          "property" : {
              "read": {
                  "task_name": "read", 
                  "filename" : "data/a.csv", 
                  "sep" :","
              }, 
              "drop" : {
                  "task_name": "drop", 
                  "column_name": "date"
              }, 
              "write" : {
                  "task_name": "write", 
                  "filename" : "data/b.csv", 
                  "sep": ","
              }
          }
      }
      
    • Server 응답

      "job_id=1 Updated OK"
    • 존재하지 않는 Job에 대한 put 요청 시 Server 응답

      {
          "message": "Updating Job added by other is forbidden",
          "status": 403
      }

  • GET /api/v1/jobs/1

    • 요청 Body

      None
      
    • Server 응답

      [
        {
          "_id": {
            "$oid": "62844f8bbade6a84942682b9"
          },
          "job_id": 1,
          "job_name": "Job1",
          "task_list": {
            "read": [
              "drop"
            ],
            "drop": [
              "write"
            ],
            "write": []
          },
          "property": {
            "read": {
              "task_name": "read",
              "filename": "data/a.csv",
              "sep": ","
            },
            "drop": {
              "task_name": "drop",
              "column_name": "date"
            },
            "write": {
              "task_name": "write",
              "filename": "data/b.csv",
              "sep": ","
            }
          }
        }
      ]


프로그램 설치 및 테스트방법

MAC OS 기준으로 설명되었습니다.

Python=3.8 이상, 그리고 MongoDB가 로컬에 설치되어 있다고 가정하고 작성하였습니다.

파이썬 설치 링크, MongoDB 설치 링크


1. 깃을 내려받는다.

% git clone https://github.com/2nd-wanted-pre-onboarding-team-A/MoaData-Wanted-A.git

2. 디렉터리 변경

% cd MoaData-Wanted-A

3. 가상환경생성 및 진입

% python -m venv venv
% source venv/bin/activate

4. 모듈 설치

% pip install --upgrade pip
% pip install -r requirements.txt

5. flask 서버 실행

% flask run
서버실행 후 같은 위치에 터미널을 하나 더 생성하고 파이썬 가상환경에 진입한다.

6. 테스트케이스 실행

% python -m unittest test.py

image

7. API GET으로 자료 요청 확인

% curl http://127.0.0.1:5000/api/v1/jobs

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.