AMITT/HTML_GENERATING_CODE/.ipynb_checkpoints/test_new_code-checkpoint.ipynb
2021-02-20 18:08:10 +00:00

468 строки
16 KiB
Plaintext
Исходник Ответственный История

Этот файл содержит неоднозначные символы Юникода

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"updated ../phase_index.md\n",
"updated ../tactic_index.md\n",
"updated ../technique_index.md\n",
"updated ../task_index.md\n",
"updated ../incident_index.md\n",
"updated ../counter_index.md\n",
"updated ../responsetype_index.md\n",
"updated ../metatechniques_index.md\n",
"updated ../actors_index.md\n",
"updated ../detections_index.md\n",
"updated ../amitt_red_framework.md\n",
"updated ../amitt_blue_framework.md\n",
"updated ../amitt_red_framework_clickable.html\n",
"Writing ../counter_tactics/TA01counters.md\n",
"Writing ../counter_tactics/TA02counters.md\n",
"Writing ../counter_tactics/TA03counters.md\n",
"Writing ../counter_tactics/TA04counters.md\n",
"Writing ../counter_tactics/TA05counters.md\n",
"Writing ../counter_tactics/TA06counters.md\n",
"Writing ../counter_tactics/TA07counters.md\n",
"Writing ../counter_tactics/TA08counters.md\n",
"Writing ../counter_tactics/TA09counters.md\n",
"Writing ../counter_tactics/TA10counters.md\n",
"Writing ../counter_tactics/TA11counters.md\n",
"Writing ../counter_tactics/TA12counters.md\n",
"updated ../tactics_by_responsetype_table.md\n",
"Writing ../metatechniques/cleaningcounters.md\n",
"Writing ../metatechniques/countermessagingcounters.md\n",
"Writing ../metatechniques/data pollutioncounters.md\n",
"Writing ../metatechniques/daylightcounters.md\n",
"Writing ../metatechniques/dilutioncounters.md\n",
"Writing ../metatechniques/diversioncounters.md\n",
"Writing ../metatechniques/frictioncounters.md\n",
"Writing ../metatechniques/metatechniquecounters.md\n",
"Writing ../metatechniques/reduce resourcescounters.md\n",
"Writing ../metatechniques/removalcounters.md\n",
"Writing ../metatechniques/resiliencecounters.md\n",
"Writing ../metatechniques/scoringcounters.md\n",
"Writing ../metatechniques/targetingcounters.md\n",
"Writing ../metatechniques/verificationcounters.md\n",
"updated ../metatechniques_by_responsetype_table.md\n",
"Writing ../resources_needed/counters.md\n",
"Writing ../resources_needed/DHScounters.md\n",
"Writing ../resources_needed/NGOcounters.md\n",
"Writing ../resources_needed/activistscounters.md\n",
"Writing ../resources_needed/adtechcounters.md\n",
"Writing ../resources_needed/civil_societycounters.md\n",
"Writing ../resources_needed/community_groupscounters.md\n",
"Writing ../resources_needed/companiescounters.md\n",
"Writing ../resources_needed/content_creatorscounters.md\n",
"Writing ../resources_needed/data_scientistcounters.md\n",
"Writing ../resources_needed/datastreamscounters.md\n",
"Writing ../resources_needed/developerscounters.md\n",
"Writing ../resources_needed/educatorscounters.md\n",
"Writing ../resources_needed/elvescounters.md\n",
"Writing ../resources_needed/factcheckerscounters.md\n",
"Writing ../resources_needed/fundingcounters.md\n",
"Writing ../resources_needed/gamesdesignerscounters.md\n",
"Writing ../resources_needed/governmentcounters.md\n",
"Writing ../resources_needed/government:policymakerscounters.md\n",
"Writing ../resources_needed/influencerscounters.md\n",
"Writing ../resources_needed/influencers:trusted_authoritycounters.md\n",
"Writing ../resources_needed/infoseccounters.md\n",
"Writing ../resources_needed/librariescounters.md\n",
"Writing ../resources_needed/mediacounters.md\n",
"Writing ../resources_needed/militarycounters.md\n",
"Writing ../resources_needed/moneycounters.md\n",
"Writing ../resources_needed/platform_admincounters.md\n",
"Writing ../resources_needed/platform_admin:adtechcounters.md\n",
"Writing ../resources_needed/platform_admin:fundingsitescounters.md\n",
"Writing ../resources_needed/platform_admin:socialmediacounters.md\n",
"Writing ../resources_needed/platform_algorithmscounters.md\n",
"Writing ../resources_needed/platform_outreachcounters.md\n",
"Writing ../resources_needed/platformscounters.md\n",
"Writing ../resources_needed/publiccounters.md\n",
"Writing ../resources_needed/public:account_ownerscounters.md\n",
"Writing ../resources_needed/religious_organisationscounters.md\n",
"Writing ../resources_needed/schoolscounters.md\n",
"Writing ../resources_needed/server_admincounters.md\n",
"updated ../resources_by_responsetype_table.md\n"
]
}
],
"source": [
"from generate_amitt_ttps import Amitt\n",
"amitt = Amitt()\n",
"amitt.generate_and_write_datafiles()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Check which amitt variables we can see from here\n",
"print('{}'.format(vars(amitt).keys()))\n",
"vars(amitt)['tactics']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TEST AREA"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>technique_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>C00001</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>C00003</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>C00004</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>C00005</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>C00006</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>C00145</td>\n",
" <td>T0046</td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>C00147</td>\n",
" <td>T0060</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>C00148</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>C00149</td>\n",
" <td>TA12</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>C00149</td>\n",
" <td>T0020</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>367 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" id technique_id\n",
"0 C00001 \n",
"1 C00003 \n",
"2 C00004 \n",
"3 C00005 \n",
"4 C00006 \n",
".. ... ...\n",
"182 C00145 T0046\n",
"183 C00147 T0060\n",
"184 C00148 \n",
"185 C00149 TA12\n",
"185 C00149 T0020\n",
"\n",
"[367 rows x 2 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"amitt.cross_counterid_techniqueid"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def splitcol(df, col, newcol, divider=','):\n",
" # Thanks https://stackoverflow.com/questions/17116814/pandas-how-do-i-split-text-in-a-column-into-multiple-rows?noredirect=1\n",
" return (df.join(df[col]\n",
" .str.split(divider, expand=True).stack()\n",
" .reset_index(drop=True,level=1)\n",
" .rename(newcol)).drop(col, axis=1))\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>resource</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>C00001</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>C00003</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>C00004</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>C00005</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>C00006</td>\n",
" <td>platform_admin:socialmedia</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>C00144</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>C00145</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>C00147</td>\n",
" <td>platform_algorithms</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>C00148</td>\n",
" <td>platform_algorithms</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>C00149</td>\n",
" <td></td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>218 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" id resource\n",
"0 C00001 \n",
"1 C00003 \n",
"2 C00004 \n",
"3 C00005 \n",
"4 C00006 platform_admin:socialmedia\n",
".. ... ...\n",
"181 C00144 \n",
"182 C00145 \n",
"183 C00147 platform_algorithms\n",
"184 C00148 platform_algorithms\n",
"185 C00149 \n",
"\n",
"[218 rows x 2 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create counters cross-tables\n",
"cross_counterid_techniqueid = splitcol(amitt.df_counters[['id', 'techniques']], \n",
" 'techniques', 'technique', '\\n')\n",
"cross_counterid_techniqueid = cross_counterid_techniqueid[cross_counterid_techniqueid['technique'].notnull()]\n",
"cross_counterid_techniqueid['technique_id'] = cross_counterid_techniqueid['technique'].str.split(' ').str[0]\n",
"cross_counterid_techniqueid.drop('technique', axis=1, inplace=True)\n",
"\n",
"cross_counterid_resource = splitcol(amitt.df_counters[['id', 'resources_needed']], \n",
" 'resources_needed', 'resource', ',')\n",
"cross_counterid_resource = cross_counterid_resource[cross_counterid_resource['resource'].notnull()]\n",
"\n",
"cross_counterid_resource"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" 117\n",
"educators 11\n",
"platform_admin 11\n",
"media 10\n",
"platform_algorithms 8\n",
"government:policymakers 8\n",
"government 7\n",
"platform_admin:socialmedia 5\n",
"public 4\n",
"influencers 3\n",
"activists 2\n",
"infosec 2\n",
"money 2\n",
"developers 2\n",
"data_scientist 2\n",
"factcheckers 2\n",
"civil_society 1\n",
"DHS 1\n",
"gamesdesigners 1\n",
"server_admin 1\n",
"military 1\n",
"public:account_owners 1\n",
"platform_admin:fundingsites 1\n",
"platforms 1\n",
"adtech 1\n",
"datastreams 1\n",
"NGO 1\n",
"content_creators 1\n",
"community_groups 1\n",
"religious_organisations 1\n",
"platform_admin:adtech 1\n",
"companies 1\n",
"elves 1\n",
"funding 1\n",
"influencers:trusted_authority 1\n",
"libraries 1\n",
"platform_outreach 1\n",
"schools 1\n",
"Name: resource, dtype: int64"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cross_counterid_resource['resource'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}