{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 人际关系的利益学算法\n",
    "\n",
    "\n",
    "1. 建立一张pandas表，每行4个参数，姓名、正能量、负能量、正负能量达到平衡的交易次数(1:1)\n",
    "\n",
    "2. 每次你给某个人好处，正能量增加。你付出，别人获利。\n",
    "\n",
    "3. 每次你损害他人的利益(从别人那儿获取好处)，负能量增加。别人付出，你获利。\n",
    "\n",
    "4. 每一次操作后，若正负能量达到平衡，则“交易次数”加一\n",
    "\n",
    "\n",
    "* 正能量 = 负能量 = 0，陌生人\n",
    "\n",
    "* 正能量 > 负能量，尝试从这个人获取好处，有困难找对方帮忙\n",
    "\n",
    "* 负能量 > 正能量，对方(以及他的直系亲属、朋友、党羽)找你帮忙，你得帮。甚至还得主动揣测对方需求，主动帮忙\n",
    "\n",
    "\n",
    "* * 正能量 > 负能量，正能量-负能量 > 个人最大承受值，你报复他人(指短时间内，一次性从别人那里获取你认为应得的利益)，你将对方加入黑名单\n",
    "\n",
    "* * 负能量 > 正能量，负能量-正能量 > 他人最大承受值，他人对你采取报复行为(指短时间内，一次性从你那里获取他们认为应得的利益)，被对方加入黑名单\n",
    "\n",
    "* * 你会更倾向于与“交易次数”高的人完成下一次交易，这些人，通常被称为好友\n",
    "\n",
    "\n",
    "> 注： 这套理论不光可以解释一堆人情世故相关的问题，还可以作为“数学模型”，让机器学会为人处世。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "table = pd.DataFrame(columns=['name', 'positive_power', 'negative_power', 'balanced_times', 'description'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "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>name</th>\n",
       "      <th>positive_power</th>\n",
       "      <th>negative_power</th>\n",
       "      <th>balanced_times</th>\n",
       "      <th>description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [name, positive_power, negative_power, balanced_times, description]\n",
       "Index: []"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "temp_table = table.append({'name': 'LiZhaoYue'}, ignore_index=True)\n",
    "\n",
    "new_table = temp_table.loc[temp_table['name'] == \"LiZhaoYue\"]\n",
    "new_table.iloc[0]['positive_power'] = 0\n",
    "new_table.iloc[0]['negative_power'] = 0\n",
    "new_table.iloc[0]['balanced_times'] = 10\n",
    "new_table.iloc[0]['description'] = \"A man who willing to listen to me\"\n",
    "\n",
    "table = table.append(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "temp_table = table.append({'name': 'YuXingYu'}, ignore_index=True)\n",
    "\n",
    "new_table = temp_table.loc[temp_table['name'] == \"YuXingYu\"]\n",
    "new_table.iloc[0]['positive_power'] = 0\n",
    "new_table.iloc[0]['negative_power'] = 0\n",
    "new_table.iloc[0]['balanced_times'] = 10\n",
    "new_table.iloc[0]['description'] = \"A man who can work together\"\n",
    "\n",
    "table = table.append(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "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>name</th>\n",
       "      <th>positive_power</th>\n",
       "      <th>negative_power</th>\n",
       "      <th>balanced_times</th>\n",
       "      <th>description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>LiZhaoYue</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>A man who willing to listen to me</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>YuXingYu</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>A man who can work together</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name positive_power negative_power balanced_times  \\\n",
       "0  LiZhaoYue              0              0             10   \n",
       "1   YuXingYu              0              0             10   \n",
       "\n",
       "                         description  \n",
       "0  A man who willing to listen to me  \n",
       "1        A man who can work together  "
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# giving(name, power_value)\n",
    "# taking(name, power_value)\n",
    "# balanced_times is automatecally calculated\n",
    "# \n",
    "\n",
    "# seek_for_help(description = None) return highest balanced_times person ralated to the description\n",
    "# can_I_help(name) return the calculated information about that person"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp_table = table.loc[table['name'] == 'YuXingYu']\n",
    "len(temp_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "Name: name, dtype: bool"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table['name'].isin(['LiZhaoYue'])"
   ]
  },
  {
   "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.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
