Apparently, when working in a factory, it may be difficult to know where and how many people are. In that case, even if the machine stops, it seems that it will not be known whether it stopped due to lack of personnel or whether the machine detected an abnormality and stopped. So, let's easily visualize where and how many people are in the factory.
Let's express the initial layout of the factory in a two-dimensional layout. It also writes it to a csv file (data.csv) so that you can edit it later.
init_map.py
import csv
landmap = [[0 for i in range(21)] for j in range(5)]
for i,line in enumerate(landmap):
print(str(i) + ":", end="")
for area in line:
print(area, end="")
print()
with open('data.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(landmap)
#Execution result
0:000000000000000000000
1:000000000000000000000
2:000000000000000000000
3:000000000000000000000
4:000000000000000000000
The image is that the workers will do this on their smartphones when they arrive at the place before starting work at the factory. First, read data.csv as a numerical value. Ask the workers to use standard input to enter where they will start working (such as Aiue with this code). Create a function that increments the number of people in the place you entered. Use a function to perform the process. Finally, write this processed content to data.csv and update data.csv.
start_arran.py
landmap=[list(map(int,line.rstrip().split(","))) for line in open('data.csv').readlines()]
import csv
a = input('Where are you')
def start_where(s):
if 'A' in s:
landmap[0][0] +=1
elif 'I' in s:
landmap[0][5] +=1
elif 'C' in s:
landmap[0][10] +=1
elif 'D' in s:
landmap[0][15] +=1
elif 'Oh' in s:
landmap[0][20] +=1
elif 'Mosquito' in s:
landmap[2][0] +=1
elif 'Ki' in s:
landmap[2][5] +=1
elif 'Ku' in s:
landmap[2][10] +=1
elif 'Ke' in s:
landmap[2][15] +=1
elif 'Ko' in s:
landmap[2][20] +=1
elif 'Service' in s:
landmap[4][0] +=1
elif 'Shi' in s:
landmap[4][5] +=1
elif 'Su' in s:
landmap[4][10] +=1
elif 'Se' in s:
landmap[4][15] +=1
elif 'So' in s:
landmap[4][20] +=1
else:
print('error')
start_where(a)
for i,line in enumerate(landmap):
print(str(i) + ":", end="")
for area in line:
print(area, end="")
print()
with open('data.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(landmap)
#Execution result
Where are you
0:000000000000000000000
1:000000000000000000000
2:000000000000000000000
3:000000000000000000000
4:000000000000000000001
Where are you
0:100000000000000000000
1:000000000000000000000
2:000000000000000000000
3:000000000000000000000
4:000000000000000000001
Where are you
0:100000000000000000000
1:000000000000000000000
2:000000000010000000000
3:000000000000000000000
4:000000000000000000001
In factories, we sometimes move the placement, and because of that, we may not know where and how many people are placed, so we will consider what to do when we move the place. Decrease the number of people in the place you used to be by -1, and add +1 to the number of people in the newly moved place.
move.py
landmap=[list(map(int,line.rstrip().split(","))) for line in open('data.csv').readlines()]
import csv
a = input('Where are you?')
b = input('Where are you going')
def now_where(s):
if 'A' in s:
landmap[0][0] -=1
elif 'I' in s:
landmap[0][5] -=1
elif 'C' in s:
landmap[0][10] -=1
elif 'D' in s:
landmap[0][15] -=1
elif 'Oh' in s:
landmap[0][20] -=1
elif 'Mosquito' in s:
landmap[2][0] -=1
elif 'Ki' in s:
landmap[2][5] -=1
elif 'Ku' in s:
landmap[2][10] -=1
elif 'Ke' in s:
landmap[2][15] -=1
elif 'Ko' in s:
landmap[2][20] -=1
elif 'Service' in s:
landmap[4][0] -=1
elif 'Shi' in s:
landmap[4][5] -=1
elif 'Su' in s:
landmap[4][10] -=1
elif 'Se' in s:
landmap[4][15] -=1
elif 'So' in s:
landmap[4][20] -=1
else:
print('error')
def move(s):
if 'A' in s:
landmap[0][0] +=1
elif 'I' in s:
landmap[0][5] +=1
elif 'C' in s:
landmap[0][10] +=1
elif 'D' in s:
landmap[0][15] +=1
elif 'Oh' in s:
landmap[0][20] +=1
elif 'Mosquito' in s:
landmap[2][0] +=1
elif 'Ki' in s:
landmap[2][5] +=1
elif 'Ku' in s:
landmap[2][10] +=1
elif 'Ke' in s:
landmap[2][15] +=1
elif 'Ko' in s:
landmap[2][20] +=1
elif 'Service' in s:
landmap[4][0] +=1
elif 'Shi' in s:
landmap[4][5] +=1
elif 'Su' in s:
landmap[4][10] +=1
elif 'Se' in s:
landmap[4][15] +=1
elif 'So' in s:
landmap[4][20] +=1
else:
print('error')
now_where(a)
move(b)
for i,line in enumerate(landmap):
print(str(i) + ":", end="")
for area in line:
print(area, end="")
print()
with open('data.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(landmap)
#Execution result
Where are you? A
Where are you going Ko
0:000000000000000000000
1:000000000000000000000
2:000000000010000000001
3:000000000000000000000
4:000000000000000000001
It's very simple and dirty code, but I've drawn programming that lets you know where and how many people are in the factory.
Each ability of the worker is summarized in Excel etc. in 5 stages in advance, and since the position of A requires a total of N abilities of hoge, Mr. A and Mr. B are automatically assigned. As a result, if the number of people is insufficient and an alert appears, it would be interesting to create an algorithm that automatically changes the staffing by adding + N to the required capacity of the place.
Recommended Posts