Commit eee87f18 authored by christian.foerster's avatar christian.foerster

progress

parent 5b4930c2
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
......@@ -78,30 +78,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig,ax=plt.subplots(2,2)\n",
"fig.text(0,0.5,r\"\\sum$\",rotation=90, verticalalignment='center')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: 'C:\\\\Users\\\\Gabi\\\\Documents\\\\Python\\\\NN\\\\Inputdata\\\\PCM_MEZ_good_shape.txt'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-cdb379e1f3ca>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mfilepath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34mr\"C:\\Users\\Gabi\\Documents\\Python\\NN\\Inputdata\\PCM_MEZ_good_shape.txt\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mcount\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mStrCount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\";\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# if this takes too long it might be the server connection... (depending on the file size)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-5-e09a27b1721e>\u001b[0m in \u001b[0;36mcount\u001b[0;34m(self, string)\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mstring\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mfile\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 11\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mline\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfile\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m+=\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mline\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstring\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'C:\\\\Users\\\\Gabi\\\\Documents\\\\Python\\\\NN\\\\Inputdata\\\\PCM_MEZ_good_shape.txt'"
]
}
],
"source": [
"filepath=r\"C:\\Users\\Gabi\\Documents\\Python\\NN\\Inputdata\\PCM_MEZ_good_shape.txt\"\n",
"count=StrCount(filepath).count(\";\")\n",
......@@ -166,12 +158,50 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[0,\n",
" 1,\n",
" 1,\n",
" 2,\n",
" 3,\n",
" 5,\n",
" 8,\n",
" 13,\n",
" 21,\n",
" 34,\n",
" 55,\n",
" 89,\n",
" 144,\n",
" 233,\n",
" 377,\n",
" 610,\n",
" 987,\n",
" 1597,\n",
" 2584,\n",
" 4181,\n",
" 6765,\n",
" 10946,\n",
" 17711,\n",
" 28657,\n",
" 46368]"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def fib(n):\n",
" fibo=[1,1]\n",
"# non-recursive\n",
"def Fibonacci2(n):\n",
" if n<=0:\n",
" raise ValueError(\"The input must be larger 0.\")\n",
" fibo=[0,1]\n",
" if n==1:\n",
" return fibo[0]\n",
" elif n==2:\n",
......@@ -180,8 +210,7 @@
" for run in range(n-2):\n",
" fibo.append(fibo[-1]+fibo[-2])\n",
" return fibo\n",
"\n",
"fib(16)"
"\n"
]
},
{
......@@ -231,7 +260,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.8"
}
},
"nbformat": 4,
......
......@@ -26,7 +26,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Write a class, that takes a filepath as an argument when it is initialized. Create a method, that takes a string as an argument and returns the number of occurances of that string in that file."
"Write a class, that takes a file as an argument when it is initialized. Create a method, that takes a string as an argument and returns the number of occurances of that string in that file."
]
},
{
......@@ -95,7 +95,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.8"
}
},
"nbformat": 4,
......
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This diff is collapsed.
This diff is collapsed.
#################################################################################################################
## Package
class Tank:
def __init__(self, level, rate, upstream_tanks=None):
self.level = level
self.rate = rate
self.upstream_tanks = upstream_tanks
return
@property # allows the method use without brackets
def Q(self):
tank_area = 1
return self.level * self.rate / tank_area
class LevelGauge:
def __init__(self,tank):
self.tank = tank
self.data = []
return
def take_measurement(self):
self.data.append(self.tank.level)
return
class Network:
def __span_network(self, i):
self.tanks[i] = Tank(levels[i], rates[i], upstream_tanks=network_structure.get(i))
if network_structure.get(i) is not None:
for tank in network_structure.get(i):
#recursion
self.__span_network(tank)
def generate(self, network_structure, levels, rates):
self.final_tank = max(network_structure.keys())
if network_structure[self.final_tank] == []:
print("The last tank has no upstream tanks. The network structure you provided is invalid.")
else:
self.tanks = {}
self.__span_network(self.final_tank)
return "network generated"
def __fill_tank(self,tank_id):
tank = self.tanks[tank_id]
if tank.upstream_tanks is not None:
for uptank_id in tank.upstream_tanks:
# recursion
self.__fill_tank(uptank_id)
uptank = self.tanks[uptank_id]
uptank.level -= uptank.Q
tank.level += uptank.Q
def install_level_gauges(self):
self.gauges = {}
for tank_id in self.tanks:
self.gauges[tank_id] = LevelGauge(self.tanks[tank_id])
def simulate(self,iterations):
for gauge in self.gauges.values():
gauge.take_measurement()
for dt in range(iterations):
self.__fill_tank(self.final_tank)
for gauge in self.gauges.values():
gauge.take_measurement()
return
#################################################################################################################
## Top level Api use
network_structure = {6:[4,5],4:[1,2],5:[3]}
levels = {1:10,2:20,3:15,4:8,5:44,6:2.5}
rates = {1:0.0,2:0.06,3:0.9,4:0.3,5:0.5,6:0}
network = Network()
network.generate(network_structure,levels,rates)
network.install_level_gauges()
network.simulate(110)
#################################################################################################################
## plotting results
import matplotlib.pyplot as plt
fig, axis = plt.subplots(6,1,figsize = (12,8))
for idx, ax in enumerate(axis):
ax.plot(network.gauges[idx+1].data)
ax.set_title(idx+1)
plt.tight_layout()
{
"ac": 33,
"abc": [
3,
4,
5
],
"bcd": 44
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment