I work in economics and I'm a newbie in programming, so please pardon my lack of technical knowledge here.
Im using iPython 2.7 and I want to analyze a production system as network. Therefore Im trying to create a network out of a csv-file. The csv-file includes two columns. First column is a representation of work orders, the second represents working stations. The work orders represent Moduls. The working stations have to be nodes of the network.
ORDER_ID,MACHINE_ID,
0,0,
0,1,
1,1,
2,2,
2,3,
2,4,
2,5,
2,6,
2,1,
2,7,
2,2,
3,8,
3,1,
4,9,
5,10,
5,10,
5,5,
5,11,
5,0,
5,12,
5,13,
As long as the OrderID has the same number, it is one modul. So in this list are five moduls. My code has to analyze the Machine distribution in a modul and this is how it looks like:
#Import Module
import networkx as nx
import csv
#Create Graph
g = nx.DiGraph()
#open File
Data = open("Data.csv")
csv_F = csv.reader(Data,delimiter=',')
Data.next()
#Algorithmus for creating Edges
prevOrder = -1
prevMachine = -1
Nodes = []
SumModul = []
for row in csv_F:
if row[0] == prevOrder:
g.add_edge(str(prevMachine),str(row[1]))
prevOrder = row[0]
prevMachine = row[1]
Nodes.append(row[1])
SumModul.append(row[0]) # Add Index to List of Moduls
QuaModul = len(list(set(SumModul))) # Quantity of Moduls
Data.close()
#Node Reuse
print "Qantity of Moduls: "+ str(QuaModul)
#Sort List of Nodes
QuantityNodes = []
for node in g.nodes():
QuantityNodes.append(int(node))
QuantityNodes.sort()
#Analysis
for sortNode in QuantityNodes: #for-Schleife der Knoten:
NodeRU = [Nodes.count(str(sortNode))]
for NRU in NodeRU:
print "Node Reuse of Node: " + str(sortNode)
print float(NRU)
print float((float(NRU)*100)/QuaModul)
My problem is that I want to count a MachineID just one time per modul. But my program is counting every distribution. So MachineID 2 appears in Modul2 2 times, but its have to be counting one time. MachineID 10 in Modul5 appears two times, as well.
I'm expecting following results:
Qantity of Moduls: 6
Node Reuse of Node: 0
2.0
33.3333333333
Node Reuse of Node: 1
4.0
66.6666666667
Node Reuse of Node: 2
1.0
16.6666666667
Node Reuse of Node: 3
1.0
16.6666666667
Node Reuse of Node: 4
1.0
16.6666666667
Node Reuse of Node: 5
2.0
33.3333333333
Node Reuse of Node: 6
1.0
16.6666666667
Node Reuse of Node: 7
1.0
16.6666666667
Node Reuse of Node: 8
1.0
16.6666666667
Node Reuse of Node: 10
1.0
16.6666666667
Node Reuse of Node: 11
1.0
16.6666666667
Node Reuse of Node: 12
1.0
16.6666666667
Node Reuse of Node: 13
1.0
16.6666666667
I guess the problem can be solved with a if-loop, but I tried different things and I can't find a solution, because of the interdependence of both column. I don't know how to manipulate the first column, because of the result of the second column.
Aucun commentaire:
Enregistrer un commentaire