--- tags: depositar-dev --- # 研究資料寄存所 資料收錄統計 技術說明 文/王禮芳 [stats.depositar.io](stats.depositar.io) 是研究資料寄存所 (depositar) 的資料收錄統計網頁。 本專案發表於 Open Repositories 2025,您可以在 [depositar](https://pid.depositar.io/ark:37281/k5w9w7145) 或 [Zenodo](https://doi.org/10.5281/zenodo.15716740) 取得摘要與簡報檔案。 ## 使用資源 ### 網頁更新與發佈 depositar stats page 利用 GitLab CI/CD 服務,每日自動更新網頁所呈現之統計資料,並且部署於 GitLab Pages 伺服器。 網頁更新分為二階段,第一階段整理 depositar 當前收錄情形(詳見[資料處理](#資料處理)),第二階段將整理好的資料呈現於網頁上(詳見[網頁前端](#網頁前端))。 ![split-pipeline-doc](https://hackmd.io/_uploads/H1xHH-eKgg.png) ### 資料處理 本專案之資料處理為一 private repository,以 [CKAN API](https://docs.ckan.org/en/2.11/api/index.html) 下載當前 depositar 之資料集收錄情形,並以 python 程式整理為兩份檔案:每日資料集狀態(圖中之 processed data)與每月統計資料(圖中之 stats data)。 此 repository 使用 [gitlab-ci-local](https://github.com/firecow/gitlab-ci-local) 在本機測試 CI 流程。 #### 專案結構 ```text . ├── code/ # 存放整理資料的程式碼 ├── dataset/ # 儲存抓取下來的資料,包含原始資料與整理後的版本 ├── frictionless_csv/ # 驗證資料與產生 Data Package 的相關程式 ├── ci_job_id.txt # 紀錄最後一筆 CI Job 的 ID ├── ci-test-local.yml # 本機執行 CI 時的 Pipeline 設定 ├── .gitlab-ci.yml # GitLab 上執行 CI 的 Pipeline 設定 ├── readme.md # 專案說明文件 ├── requirements.txt # 程式所需的相依套件 ├── update_time.txt # 紀錄資料最後更新的時間 └── .gitignore # Git 忽略規則檔 ``` #### 每日資料集狀態(processed data) 每日產生一 .csv 檔案,以各資料集作為列(row),各個欄位(column)紀錄該資料集於該欄位的資訊,例如資料集的名稱、網址、標籤、產製者等等。 檔案以 [Frictionless-py](https://framework.frictionlessdata.io/) 產生 datapackage.json 檔案並進行驗證。 #### 每月統計資料(stats data) 每日更新當月的 .csv 檔案,以每日資料集的統計狀態作為列(row),各個欄位(column)紀錄該該日裡,整個 depositar 網站的統計數值,例如該日裡 depositar 的總資料集數、所有標籤總數、所有產製者總數等等。 檔案以 [Frictionless-py](https://framework.frictionlessdata.io/) 產生 datapackage.json 檔案並進行驗證。 ### 網頁前端 depositar stats page 是一靜態網頁,使用多種前端函式庫進行網頁排版、圖表繪製、函式庫版本管理以及其他互動功能。 * [Parcel](https://parceljs.org/) - 網頁應用程式打包工具 * [Bootstrap](https://getbootstrap.com/) - 網頁排版函式庫 * [D3.js](https://d3js.org/) - js 函式庫,多樣且客製化的圖表繪製 * [DataTables](https://datatables.net/) - js 函式庫,為表格提供多樣功能 * [Select2](https://select2.org/) - js 函式庫,功能更加多元的下拉式表單 * [i18next](https://www.i18next.com/) - js 函式庫,使網頁支援雙語介面 #### 專案結構 ```text . ├── public/ # 前端資源資料夾 │ ├── css/ # 樣式表(CSS) │ ├── static/ # 靜態資源(圖片、影片等) │ ├── dataset/ # 資料集檔案 │ ├── script/ # JavaScript 網頁程式 │ ├── dataset.html # 資料集統計頁面 │ ├── history.html # 資料集趨勢頁面 │ ├── index.html # 首頁 │ ├── metadata.html # 後設資料整備情況頁面 │ └── index.js # 提供給 Parcel 打包的進入點 ├── readme.md # 專案說明文件 ├── package.json # npm 套件與專案設定 ├── .gitlab-ci.yml # GitLab CI/CD 設定檔 └── .gitignore # Git 忽略規則檔 ``` ## 本機建置 若想在本機搭建 stats.depositar.io ,可以依照以下步驟: ### 1. 下載 repo ```bash git clone git@gitlab.com:depositar/stats-page.git ``` ### 2. 安裝環境 依照指示安裝 [nvm](https://github.com/nvm-sh/nvm) 與 [node.js](https://nodejs.org/en/download) ### 3. 安裝 npm 相依套件 ```bash npm install ``` ### 4. 本機搭建 以此在本機伺服器啟動網頁: ``` npm run start ``` 若內容有所更動,以此重新建置: ``` npm run build ``` 若要清空本機已建置的網頁,以此清除快取檔: ``` npm run clean ``` ## datapackage 欄位 本專案的統計資料來自兩份 csv 檔案,一以日為單位,一為以月為單位。以下簡要介紹兩份檔案的 datapackage 欄位。 ### 逐日統計 此檔案存放於[專案 repo](https://gitlab.com/depositar/stats-page/) 中的 `public/dataset/processed_data/當日資料夾/` | 欄位名稱 | 型別 | 說明 | 範例 | |----------|------|------|------| | `title` | string | 資料集標題 | `"清代汛塘分布"` | | `name` | string | 資料集名稱(必填、唯一) | `"rc06"` | | `id` | string (uuid) | 資料集 ID(必填、唯一) | `"829b127c-e008-413d-89a0-adb991929714"` | | `groups` | array | 資料集主題 | `[ { "display_name": "[ISO19115] 水文資訊類 / Inland Waters", "name": "inland-waters" } ]` | | `num_tags` | integer | 標籤數量(≥0) | `2` | | `tags` | array | 標籤列表 | `[ { "display_name": "海洋健康指標", "name": "海洋健康指標" } ]` | | `organization` | object | 所屬專案資訊 | `{ "name": "ltser-lyudao", "title": "LTSER Lyudao 長期社會生態核心觀測綠島站" }` | | `author` | string | 資料集產製者(必填) | `"中央研究院人社中心GIS專題中心:台灣歷史文化地圖"` | | `data_type` | array | 資料類型(必填,1~15 項) | `["science", "Plain text"]` | | `license_id` | array | 授權 ID(必填) | `["notspecified"]` | | `keywords` | array | wikidata 關鍵字 | `["Q10901446"]` | | `num_resources` | integer | 資源數量(≥0) | `12` | | `tracking_summary` | object | 瀏覽統計(recent 為 2 週內瀏覽數、total 為歷史總瀏覽數) | `{ "recent": 2, "total": 2 }` | | `res_format` | object | 資源檔案格式數量 | `{ "SHP": 2, "HTML": 1 }` | | `dataset_filled_fields` | object | 後設資料填寫狀況(24 欄位,1=有填寫,0=未填寫) | `{ "title": 1, "name": 1, "notes": 1, ... }` | | `resources_filled_fields` | array | 各資源的後設資料填寫狀況 | `[ { "url": 1, "name": 1, "format_str": "IPYNB" } ]` | ### 逐月統計 此檔案存放於[專案 repo](https://gitlab.com/depositar/stats-page/) 中的 `public/dataset/statsdata_data/當月資料夾/` | 欄位名稱 | 型別 | 說明 | 範例 | |----------|------|------|------| | `update_time` | datetime | 本次統計更新時間(必填、唯一) | `"2023-12-30T20:34:59Z"` | | `num_datasets` | integer | 當前資料集總數(必填,≥0) | `750` | | `groups` | array | 各主題下的資料集數量 | `[ { "name": "geography-and-places", "display_name": "03. 地理與地方 / Geography and places", "count": 66 } ]` | | `tags` | array | 各標籤在所有資料集中的使用次數統計 | `[ { "name": "LTSER Changhua", "display_name": "LTSER Changhua", "count": 7 } ]` | | `organizations` | array | 各專案底下的資料集數量 | `[ { "name": "ecocheck_taichung_2018", "display_name": "107年度台中市生態檢核工作計畫", "count": 4 } ]` | | `authors` | array | 各產製者創造的資料集數量 | `[ { "display_name": "高雄市政府水利局", "count": 7 } ]` | | `data_types` | array | 各類資料類型的數量統計 | `[ { "name": "database", "display_name": "資料庫", "count": 59 } ]` | | `license_ids` | array | 各授權方式的數量統計 | `[ { "name": "notspecified", "display_name": "授權條款未指定", "count": 1325 } ]` | | `keywords` | array | 各 Wikidata keyword 的數量統計(含中英文標籤) | `[ { "name": "Q11070045", "display_name": "Q11070045", "count": 61, "en_label": { "language": "en", "value": "Changhua County Government" }, "zh_tw_label": { "language": "zh-tw", "value": "彰化縣政府" } } ]` | | `resources_formats` | array | 資料集資源的檔案格式數量統計(`count`=檔案數量,`persence`=使用過的資料集數) | `[ { "display_name": "PDF", "count": 4336, "persence": 1501 } ]` | | `datasets_filled_stats` | object | 資料集層級後設資料填寫狀況(統計各欄位填寫的資料集數) | `{ "title": 2210, "name": 2210, "license_id": 2210, ... }` | | `resources_filled_stats` | object | 資源層級後設資料填寫狀況(統計各欄位填寫的資料集資源數) | `{ "url": 7711, "name": 7681, "format": 7538, ... }` | | `num_resources` | integer | 當前資源總數(必填,≥0) | `8100` |