SHARE
TWEET

Untitled

a guest May 25th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "code",
  5.    "execution_count": 1,
  6.    "metadata": {},
  7.    "outputs": [],
  8.    "source": [
  9.     "from datetime import date\n",
  10.     "import logging\n",
  11.     "\n",
  12.     "import iatikit\n",
  13.     "\n",
  14.     "\n",
  15.     "logging.getLogger().setLevel(logging.ERROR)"
  16.    ]
  17.   },
  18.   {
  19.    "cell_type": "code",
  20.    "execution_count": 2,
  21.    "metadata": {},
  22.    "outputs": [],
  23.    "source": [
  24.     "# collect all v1.0x datasets\n",
  25.     "datasets = []\n",
  26.     "for x in iatikit.data().datasets:\n",
  27.     "    if not x.validate_xml():\n",
  28.     "        continue\n",
  29.     "    if x.version.startswith('1'):\n",
  30.     "        datasets.append(x)"
  31.    ]
  32.   },
  33.   {
  34.    "cell_type": "code",
  35.    "execution_count": 3,
  36.    "metadata": {},
  37.    "outputs": [
  38.     {
  39.      "name": "stdout",
  40.      "output_type": "stream",
  41.      "text": [
  42.       "Total v1.0x organisation datasets: 116\n"
  43.      ]
  44.     }
  45.    ],
  46.    "source": [
  47.     "total_org_datasets = len([x for x in datasets if x.filetype == 'organisation'])\n",
  48.     "print(f'Total v1.0x organisation datasets: {total_org_datasets:,}')"
  49.    ]
  50.   },
  51.   {
  52.    "cell_type": "code",
  53.    "execution_count": 4,
  54.    "metadata": {},
  55.    "outputs": [
  56.     {
  57.      "name": "stdout",
  58.      "output_type": "stream",
  59.      "text": [
  60.       "Total v1.0x activity datasets: 594\n"
  61.      ]
  62.     }
  63.    ],
  64.    "source": [
  65.     "total_act_datasets = len([x for x in datasets if x.filetype == 'activity'])\n",
  66.     "print(f'Total v1.0x activity datasets: {total_act_datasets:,}')"
  67.    ]
  68.   },
  69.   {
  70.    "cell_type": "code",
  71.    "execution_count": 5,
  72.    "metadata": {},
  73.    "outputs": [
  74.     {
  75.      "name": "stdout",
  76.      "output_type": "stream",
  77.      "text": [
  78.       "Total v1.0x activities: 68,698\n"
  79.      ]
  80.     }
  81.    ],
  82.    "source": [
  83.     "total_acts = sum([len(x.activities) for x in datasets])\n",
  84.     "print(f'Total v1.0x activities: {total_acts:,}')"
  85.    ]
  86.   },
  87.   {
  88.    "cell_type": "code",
  89.    "execution_count": 6,
  90.    "metadata": {},
  91.    "outputs": [
  92.     {
  93.      "name": "stdout",
  94.      "output_type": "stream",
  95.      "text": [
  96.       "Total v1.0x activities with status 1 or 2: 24,125\n"
  97.      ]
  98.     }
  99.    ],
  100.    "source": [
  101.     "query = 'activity-status/@code=\"1\" or activity-status/@code=\"2\"'\n",
  102.     "total_live_acts = sum([\n",
  103.     "    dataset.activities.where(xpath=query).count()\n",
  104.     "    for dataset in datasets])\n",
  105.     "print(f'Total v1.0x activities with status 1 or 2: {total_live_acts:,}')"
  106.    ]
  107.   },
  108.   {
  109.    "cell_type": "code",
  110.    "execution_count": 7,
  111.    "metadata": {},
  112.    "outputs": [
  113.     {
  114.      "name": "stdout",
  115.      "output_type": "stream",
  116.      "text": [
  117.       "Total v1.0x activities with end date in the future: 28,057\n"
  118.      ]
  119.     }
  120.    ],
  121.    "source": [
  122.     "total_future_acts = 0\n",
  123.     "for dataset in datasets:\n",
  124.     "    for activity in dataset.activities:\n",
  125.     "        if activity.end and activity.end < date.today():\n",
  126.     "            continue\n",
  127.     "        total_future_acts += 1\n",
  128.     "print(f'Total v1.0x activities with end date in the future: ' +\n",
  129.     "      f'{total_future_acts:,}')"
  130.    ]
  131.   }
  132.  ],
  133.  "metadata": {
  134.   "kernelspec": {
  135.    "display_name": "Python 3",
  136.    "language": "python",
  137.    "name": "python3"
  138.   },
  139.   "language_info": {
  140.    "codemirror_mode": {
  141.     "name": "ipython",
  142.     "version": 3
  143.    },
  144.    "file_extension": ".py",
  145.    "mimetype": "text/x-python",
  146.    "name": "python",
  147.    "nbconvert_exporter": "python",
  148.    "pygments_lexer": "ipython3",
  149.    "version": "3.6.0"
  150.   }
  151.  },
  152.  "nbformat": 4,
  153.  "nbformat_minor": 2
  154. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top