윤혜원

bs selection algorithm and save internet activity predictions

No preview for this file type
1 +{
2 + "cells": [
3 + {
4 + "cell_type": "code",
5 + "execution_count": 2,
6 + "metadata": {},
7 + "outputs": [
8 + {
9 + "name": "stdout",
10 + "output_type": "stream",
11 + "text": [
12 + " Unnamed: 0 gridID Internet Activity Prediction\n",
13 + "0 0 1 9952.919155\n",
14 + "1 0 2 10007.809479\n",
15 + "2 0 3 12864.899626\n"
16 + ]
17 + }
18 + ],
19 + "source": [
20 + "import pandas as pd\n",
21 + "df = pd.read_csv('predictions.csv')\n",
22 + "#sort internet activity prediction\n",
23 + "df.sort_values(by=['Internet Activity Prediction'],inplace=True)\n",
24 + "print(df)\n"
25 + ]
26 + },
27 + {
28 + "cell_type": "code",
29 + "execution_count": 13,
30 + "metadata": {},
31 + "outputs": [
32 + {
33 + "name": "stdout",
34 + "output_type": "stream",
35 + "text": [
36 + "g1 cache remainder size 137\n",
37 + "g2 cache remainder size 582\n",
38 + "g3 cache remainder size 867\n",
39 + "contents size 821\n",
40 + "[[3, 867]]\n"
41 + ]
42 + }
43 + ],
44 + "source": [
45 + "from random import seed\n",
46 + "from random import randint\n",
47 + "seed(1)\n",
48 + "g1_cache=randint(0,1000)\n",
49 + "g2_cache=randint(0,1000)\n",
50 + "g3_cache=randint(0,1000)\n",
51 + "\n",
52 + "contents_cache=randint(0,1000)\n",
53 + "\n",
54 + "print(\"g1 cache remainder size\" , g1_cache)\n",
55 + "print(\"g2 cache remainder size\" ,g2_cache)\n",
56 + "print(\"g3 cache remainder size\" ,g3_cache)\n",
57 + "print(\"contents size\" ,contents_cache)\n",
58 + "\n",
59 + "l_bs_cache=[]\n",
60 + "if(contents_cache<g1_cache):\n",
61 + " arr=[1,g1_cache]\n",
62 + " l_bs_cache.append(arr)\n",
63 + "if(contents_cache<g2_cache):\n",
64 + " arr=[2,g2_cache]\n",
65 + " l_bs_cache.append(arr)\n",
66 + "if(contents_cache<g3_cache):\n",
67 + " arr=[3,g3_cache]\n",
68 + " l_bs_cache.append(arr)\n",
69 + "\n",
70 + "print(l_bs_cache)"
71 + ]
72 + },
73 + {
74 + "cell_type": "code",
75 + "execution_count": 22,
76 + "metadata": {},
77 + "outputs": [
78 + {
79 + "name": "stdout",
80 + "output_type": "stream",
81 + "text": [
82 + "[1, 9.18594536053351, 45.47304470082458]\n",
83 + "[2, 9.193139700323409, 45.46987577194055]\n",
84 + "[3, 9.195377006955539, 45.46770952221271]\n"
85 + ]
86 + }
87 + ],
88 + "source": [
89 + "import random\n",
90 + "import sys\n",
91 + "import math\n",
92 + "#milan lat,lon\n",
93 + "latitude = 45.4654219\n",
94 + "longitude = 9.1859243\n",
95 + "bs_locations=[]\n",
96 + "def generate_random_data(lat, lon):\n",
97 + " for i in range(1,4):\n",
98 + " dec_lat = random.random()/100\n",
99 + " dec_lon = random.random()/100\n",
100 + " arr=[i, lon+dec_lon, lat+dec_lat]\n",
101 + " print(arr)\n",
102 + " bs_locations.append(arr)\n",
103 + "\n",
104 + "generate_random_data(latitude, longitude)\n"
105 + ]
106 + },
107 + {
108 + "cell_type": "code",
109 + "execution_count": 34,
110 + "metadata": {},
111 + "outputs": [
112 + {
113 + "name": "stdout",
114 + "output_type": "stream",
115 + "text": [
116 + "(9.194398637369373, 45.466765542441124)\n",
117 + "[[3, 0.1499061393976395, 867]]\n",
118 + " gridID distance internet traffic prediction\n",
119 + "0 3 0.149906 867\n",
120 + "0.1499061393976395\n",
121 + "bs selection result: 3\n"
122 + ]
123 + }
124 + ],
125 + "source": [
126 + "import geopy.distance\n",
127 + "seed(1)\n",
128 + "dec_lat = random.random()/100\n",
129 + "dec_lon = random.random()/100\n",
130 + "request_location=(longitude+dec_lon, latitude+dec_lat)\n",
131 + "print(request_location)\n",
132 + "\n",
133 + "bs_distances=[]\n",
134 + "for bs in l_bs_cache:\n",
135 + " grid_num=bs[0]\n",
136 + " for l in bs_locations:\n",
137 + " if(l[0]==grid_num):\n",
138 + " coords_1=(l[1],l[2])\n",
139 + " dist=geopy.distance.geodesic(coords_1, request_location).km\n",
140 + " arr=[grid_num,dist,bs[1]]\n",
141 + " bs_distances.append(arr)\n",
142 + "#[gridID, distance, traffic]\n",
143 + "print(bs_distances)\n",
144 + "\n",
145 + "#sort bs_distances\n",
146 + "col=['gridID','distance','internet traffic prediction']\n",
147 + "df=pd.DataFrame(bs_distances, columns=col)\n",
148 + "df.sort_values(by=['distance'], inplace=True)\n",
149 + "print(df)\n",
150 + "\n",
151 + "min_value=df['distance'][0]\n",
152 + "grid_num=df['gridID'][0]\n",
153 + "print(min_value)\n",
154 + "count_row=df.shape[0]\n",
155 + "for x in range(count_row):\n",
156 + " if(df.loc[x]['distance']<min_value):\n",
157 + " min_value=df.loc[x]['distance']\n",
158 + " grid_num=df.loc[x]['gridID']\n",
159 + " \n",
160 + "print(\"bs selection result: \",grid_num)"
161 + ]
162 + },
163 + {
164 + "cell_type": "code",
165 + "execution_count": null,
166 + "metadata": {},
167 + "outputs": [],
168 + "source": []
169 + }
170 + ],
171 + "metadata": {
172 + "kernelspec": {
173 + "display_name": "Python 3",
174 + "language": "python",
175 + "name": "python3"
176 + },
177 + "language_info": {
178 + "codemirror_mode": {
179 + "name": "ipython",
180 + "version": 3
181 + },
182 + "file_extension": ".py",
183 + "mimetype": "text/x-python",
184 + "name": "python",
185 + "nbconvert_exporter": "python",
186 + "pygments_lexer": "ipython3",
187 + "version": "3.7.7"
188 + }
189 + },
190 + "nbformat": 4,
191 + "nbformat_minor": 4
192 +}
1 -import pandas as pd
2 -from tqdm import tqdm
3 -
4 -data=open("sms-call-internet-mi-2013-11-01.txt").read()
5 -lines_of_data=data.splitlines()
6 -tmp = []
7 -for i in tqdm(range(len(lines_of_data))):
8 - tmp.append(lines_of_data[i].split())
9 -data_df = pd.DataFrame(tmp)
10 -data_df.to_csv('dataset.csv')
11 -data_df.shape
12 -data_df.ndim
13 -
1 +,gridID,Internet Activity Prediction
2 +0,1,9952.919154515539
3 +0,2,10007.809478855686
4 +0,3,12864.899626276776
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.