Coder Social home page Coder Social logo

camera-trap-api's People

Contributors

ckotwn avatar dca avatar dependabot[bot] avatar jeremy60607 avatar kelp404 avatar moogoo78 avatar onetail avatar rwu823 avatar ts00617355 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

camera-trap-api's Issues

Fix all ESLint rules

Once #6 PR is merged. we'll get many errors. like this, 😅

image

So anyone can help to fix it?

cc @cjk-halodule

5.1 5.2 上傳流程 判斷邏輯

(後端網站service處理部分)

  • 判斷是否為 ZIP

    • 是 CSV+Media
      • 格式檢查
      • 正確性檢查
      • 一致性檢查
      • 不通過:回傳錯誤訊息
    • 是 全部都是 Media
    • 否 單個 Media
    • 否 單個 CSV
      • 格式檢查
      • 正確性檢查
      • 不通過:回傳錯誤訊息
  • 重覆性檢查

10 個人設定

10.1.1 登出

  • 前端登出後,一併清理後端 API 用的 session 資料

10.1.2 設定

  • 修改使用者名稱與電子郵件
    post to /ctp-user/bulk-update
[{
  "_id": OrcID_XXXX-XXXX-XXXX-XXXX,
  "$set": {
    "name": "New Name",
    "email": "New Email"
  }
}]
  • 文件

10.1.2 快速鍵設定

  • Model 建立 (至少要 _id (md5 of user_id:projectTitle), userId, projectTitle, speciesHotKey: [{species, hotKey}, ...])
  • 讀取、儲存用的 API (可先掛上 bulk-update with $upsert)

Related to TaiBIF/camera-trap-webapp#69

11.1 通知

  • 依照通知類型設計 model ,或直接從既有 model 中調整、讀取通知相關資訊。
    通知類型包含:
    • (a) 申請欄位通知
    • (b) 問題回報 / 意見反饋通知
    • (c) 通過欄位申請
    • (d) 相機異常回報
    • (e) 上傳結果通知
    • (f) 系統管理員意見反饋回覆通知
    • (g) 系統通知
  • 依照計畫、角色、登入使用者等資訊篩選登入使用者應看到哪些通知。
  • API 設計
  • API 文件

Related to TaiBIF/camera-trap-webapp#57

2.8.1 林班地資料 endpoint

TaiBIF/camera-trap-webapp#18 相關
需要送出林班地 JSON 供前端套疊

  • 取得林班地資料 in KMZ
  • 轉換 KMZ to GeoJSON
  • normalize GeoJSON 減少體積
  • 按事業處分檔
  • 寫入資料庫 db.createCollection("ForestCompartmentBoundary", options)
  • 建立 API 接口 /forest-compartment-boundary (with user verification)

Expected POST application/json object:

{
  "decimalLatitude": "24.564853",
  "decimalLongitude": "120.991452"
}

Expected response application/json

{ 
  "query": {
    "decimalLatitude": "24.2849853",
    "decimalLongitude": "120.7340352"
  },
  "results": [
    {
      "type": "Feature",
      "properties": {
        "Name": "東勢處",
        "description": null,
        "altitudeMode": "clampToGround",
        "CMPT": "3",
        "AREA": "790277.780053",
        "WKNG": "8",
        "FID": "1",
        "DIST_C": "東勢處",
        "DIST": "03",
        "Field_1": "東勢處",
        "WKNG_C": "八仙山" },
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [ [ [ [ 120.734243717809093, 24.284491143322999 ], [ 120.734545820319696, 24.284567597614569 ], [ 120.734410083969905, 24.285020350672809 ], [ 120.734291023148501, 24.285417040780661 ], [ 120.734284836437496, 24.285437653505401 ], [ 120.734278135904702, 24.28547086374072 ], [ 120.734195237479099, 24.285748970890761 ], [ 120.734065208922004, 24.285852237639141 ], [ 120.734057016677795, 24.285836377101269 ], [ 120.734056278880601, 24.28583495100635 ], [ 120.734056250359899, 24.285823104678268 ], [ 120.733962132776696, 24.285516133988011 ], [ 120.733744241223306, 24.284804710222581 ], [ 120.733844003884897, 24.284739381894511 ], [ 120.7338193504401, 24.2846068229106 ], [ 120.733756587505795, 24.28427007817363 ], [ 120.733906834895095, 24.284234843986361 ], [ 120.734354091737401, 24.284129957898259 ], [ 120.734243717809093, 24.284491143322999 ] ] ] ]        }
    }
  ]
}

When no intersect:

{
  "message": "No compartment found.",
  "coordinate": {
    "decimalLatitude": "24.564853",
    "decimalLongitude": "120.991452"
  }
}

As this is an independent service endpoint, two files are expected in /common/models/

  1. forest-compartment-boundary.js
  2. forest-compartment-boundary.json

Model name would be: ForestCompartmentBoundary

參考

  1. MongoDB Geospatial Queries
  2. StrongLoop example

不過應該是不會需要 loopback 特別的支援,這裡是需要 point-in-polygon 的 mongo query 再把 GeoJSON object 送出來即可。

8. 資料匯出

  • on demand 獨立 API 後端用完整資料(不分頁)產生 CSV,要檢查使用者權限
    - [ ] 傳到 S3
  • 提供是否已產生完成的訊息
  • 提供 CSV 下載連結

Related to #19
Related to TaiBIF/camera-trap-webapp#67

7.4 有效照片與目擊事件,7.5 初測延遲

Must have

  • 7.4 API 接口 接受前端查詢條件,執行計算
  • 7.5 API 接口 接受前端查詢條件,執行計算
  • 7.4 計算程式開發
  • 7.5 計算程式開發
  • 7.4 計算完成回傳結果
  • 7.5 計算完成回傳結果

Good to have

  • 每次計算紀錄條件及 log
  • log 包含時間
    需要前端介面提供顯示 log 的地方

Related to TaiBIF/camera-trap-webapp#55

新增 API 提供錯誤數量

若相機位置有錯誤資料,相機位置的名稱後方會有「錯誤數量的提示」

新增 API
GET /project/{id}/multimedia-annotation-error-cameras?site=&subSite=

{
  "results": [
    {
      "site": "苗栗",
      "subSite": "南庄鄉田美村",
      "cameraLocation": "HC20B",
      "errorCount": 255
    },
    {
      "site": "苗栗",
      "subSite": "南庄鄉田美村",
      "cameraLocation": "HC20A",
      "errorCount": 480
    }
  ]
}

回傳結果為依據 MultimediaAnnotation.multimedia_error_flag 為 true 的資料進行 group。

2018-11-25 9 53 40

API project deployment workflow

  • 確認目前的 API 是否在 eb 上
  • workflow only on github
  • make sure github has the latest version
  • current method of API deployment
  • deploy ac2cb3f to eb

Current manual deployment:

  • ZIP the following items
  .ebextensions
  client
  common
  server
  package.json

https://api.camera-trap.tw

  • 建立 DNS entry
  • 將 DNS 指向 api-dev (CameraTrapApi-env)
  • nginx 設定加上 port 443 for api.camera-trap.tw

3.6 計畫成員

  • Suggest endpoint /project/{$projectId}/user/add, instead of /project/add-user-to-project
  • Implement /project/{$projectId}/user/delete/{$userId}
  • Main script to work on:
    TaiBIF/camera-trap-api/blob/master/common/models/ctp-user.js

Post

{
  "userId": $userId, // OrcID_XXXX-XXXX-XXXX-XXXX
  "projectId": $projectId, // 欲加入的計畫id
  "role": $role // 角色,
}

Response

{
  "userId": $userId, // OrcID_XXXX-XXXX-XXXX-XXXX
  "projectId": $projectId, // 欲加入的計畫id
  "projectTitle": "", 加入計畫名稱 
  "name": "", // 姓名
  "email": "", // 電子郵件
  "role": $role // 角色,
}

Related to TaiBIF/camera-trap-webapp#64

登入機制重構

current authentication:

try {
  // TODO: camera-trap-user-id 只在測試環境使用,正式環境要把這個 headers 拿掉
  userId = req.headers['camera-trap-user-id'] || req.session.user_info.userId;
} catch (e) {
  callback(new errors.Http403('使用者未登入'));
}

current login flow:
set-cookie

問題:

  1. 跨域名 ajax response 的 set-cookie 是不會被寫進去的。
  2. 正式上線後我們不應該用 headers['camera-trap-user-id'] 來認使用者,任何人只要知道使用者 id 後就能用他的身份登入。
  3. 如果沒有 session 的話下載 csv 相關的功能都失效。 #29

7.1 資料篩選及下載

Must have

  • Query request 樣板設計
  • 提供 CSV 是否已成功產生的 log info
  • 提供下載 CSV 的連結

Good to have

  • 儲存查詢條件/快取查詢結果
    前端要有地方問使用者是否直接下載同查詢的快取結果,並提供前次查詢時間供使用者參考

Related to #24

4.17 錯誤提示格式

  • 物種不在預設中
  • 在文件中標示如何儲存錯誤提示。
    - [ ] 相片時間不合理
    - [ ] 檔名不連續
    - [ ] 相機疑似異常
    - [ ] 偵測到非3連拍,請注意相機狀況或設定

Related to TaiBIF/camera-trap-webapp#44

辨識及回收進度的更後更新時間

最後更新時間定義上是該選定範圍最近一筆更動(回收或辨識)過的資料
所以是比較 location-month-identified-num.js 及 location-month-retrieved-num.js 的資料集中最新的一筆來顯示時間。

此處 同一查詢條件的資料結果找出最新的一筆為最後更新時間,亦即 modified 欄位。

目標的 JSON 格式應如 辨識回收 文件說明。

Related to TaiBIF/camera-trap-webapp#16

[Suggestion] Misc

  • Unified file naming (I think _ is not generally convention in JS community.)
    e.g.
    https://github.com/TaiBIF/camera-trap-api/blob/master/server/boot/create_indexes.js

  • ESLint rules should extend Airbnb and integrate pre-commit hooks (also prettier).

  • Separate out ESLint rules for easy to share in each repo (maybe is called TaiBIF/eslint-base )

  • CI/CD integration.

  • Until / API testing.

  • Remove sensitive information switch to .env instead of.

  • Don't put builded code in repository.

  • Add node in package.json

  • use yarn instead of npm (optional but strongly recommend.)

  • clean up unnecessary packages

    • eslint-plugin-react
    • serve-favicon
    • ...etc

500 or 502 response

@oahehc mentioned:

/project/related-to-me => 500
/announcement/query => 502
/ctp-user/me => 500
/announcement/notifications => 502

Tests needed for ensuring API functioning

While we are improving code quality and applying eslint rules, we need tests to ensure the API functioning as expected, in other words, not breaking the working state.

@trashmai can you please write such tests so others can work on code with peace in mind? Thanks.

dev mongo instance

目前開發環境 dev api 後面的 MongoDB 是放在中研院,應該要一併部署到 AWS。
@rwu823 正著手進行 AWS Elastic Beanstalk 環境的自動化建置,也建立了 api-dev 環境。

  • 我們需要先以目前中研院的 MongoDB 規格,建一個在 AWS 中。
  • 該必要設定使 api-dev 的應用程式可與此 DB 互動,及 api-dev 將基於此 DB
  • dev 使用不需要 replicate or load balancing
  • DB 帳密的資料移出 server/datasource.json
  • 自動建置 dev-api 環境建置此 db 並匯入測試資料?
  • 順暢後以相同方式部署 prod 環境,DB 則有跨 AZ 的 replicate

Related to #26

新增 API 一次取得所有樣區是否有錯誤

TaiBIF/camera-trap-webapp#44 (comment)

新增 API
GET /project/{id}/multimedia-annotation-error-sites

{
  "results": [
    {
      "site": "新竹",
      "subSite": "南庄30林班",
      "errorCount": 142
    },
    {
      "site": "臺東處",
      "subSite": "NULL",
      "errorCount": 2127
    },
    {
      "site": "苗栗",
      "subSite": "南庄鄉田美村",
      "errorCount": 735
    }
  ]
}

回傳結果為依據 MultimediaAnnotation.multimedia_error_flag 為 true 的資料進行 group。

2018-11-25 9 56 36

3.1 計畫管理 (計畫基本資訊)

應該會有一支 API for 計畫基本資訊編輯?
image

畫面可編輯的欄位如下

    "projectTitle": "測試計畫1 // 計畫名稱",
    "shortTitle": "測1 // 計畫簡稱",
    "funder": "林務局 // 委辦單位",
    "projectId": "FB-test-cameratrap-01 // 計畫編號",
    "principalInvestigator": "測試principalInvestigator // 計畫主持人",
    "projectStartDate": "2018-10-15 // 計畫時間:起",
    "projectEndDate": "2018-12-10 // 計畫時間:迄",
    "adminArea": [ // 計畫地區, 見 WF 2.3.7
      "苗栗縣",
      "新竹縣"
    ],
    "abstract": "// 計畫摘要",
    "remarks": "// 備註",

log management

系統的 log 處理應該按照類別 (status, debug, error ...) 紀錄在可以設定的位置,避免直接輸出在 console 中。

需要一個訊息單元統一處理系統端(logging)及需要送到 response 的狀態。

時間數值的一致格式

目前從 API 文件來看,日期格式有:

"dailyTestTime": [ // 可先略過這項
          {
            "since": 1539593959,
            "time": "12:00:00"
          }
        ],
"projectStartDate": "2018-10-15 // 計畫時間:起",
"projectEndDate": "2018-12-10 // 計畫時間:迄",
"abnormalStartDate": "2017/02/08", // 異常資料時間 起
"abnormalEndDate": "2017/03/01", // 異常資料時間 迄
      "created": 1540788756.494,
      "modified": 1542014471.609,
      "corrected_date_time": "2017-02-09 17:28:29",
  • 應決定一致的 API 時間儲存格式
  • 應決定一致的前端時間顯示格式
  • 時間格式應在 key 命名中指明,或在 API 文件中說明

3.2.3 新增欄位表單的 API

For role: ProjectManager | Researcher

endpoint: project/data-field/add

3.2.3 彈出對話框的欄位有:

  • 欄位名稱
  • 欄位形式
  • 輸入格式
  • 備註

預期在 3.2.3 按下確定送出時,後端的 project/{$projectId}/data-field/add 及接受的 POST 格式:

{
  "projectId" : "",
  "userId" : "OrcId-*",
  "key" : "", // (留空)
  "label" : "", // 角況
  "widget_type" : "", // select | string | datePicker
  "widget_date_format" : "", // YYYY-MM-DD hh:mm
  "widget_select_options" : [
    {
      "key" : "", // (留空)
      "label" : "", // 例如性別 M | F
    },
    {
      "key" : "", // (留空)
      "label" : "", // 例如年齡 juvenile | adult
    },
  ],
  "description" : "", // 備註內容
  "fieldStatus" : "", // pending | approved | rejected
}

系統收到 POST 物件後存入 db.DataFieldAvailable 中並傳回新增物件內容在 response 中:

{
  "message" : "Request successfully submitted."
  "dataFieldDefinition" : {
    "projectId" : "",
    "userId" : "OrcId-*",
    "key" : "", // (留空)
    "label" : "", // 角況
    "widget_type" : "", // select | string | datePicker
    "widget_date_format" : "", // YYYY-MM-DD hh:mm
    "widget_select_options" : [
      {
        "key" : "", // (留空)
        "label" : "", // 例如性別 M | F
      },
      {
        "key" : "", // (留空)
        "label" : "", // 例如年齡 juvenile | adult
      },
    ],
    "description" : "", // 備註內容
    "fieldStatus" : "pending",
    "created" : 1543110609.074,
    "modified" : 1543110609.074
  }
}
  • 然後將此 JSON 寄給系統管理員(電子郵件)。
  • 若有錯誤則回傳錯誤代碼,亦將 POST 物件及 error 內容寄給系統管理員。
  • 前端則據以顯示對話框通知成功或失敗。

Related to TaiBIF/camera-trap-webapp#52

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.