Difference between revisions of "Statistical Algorithms Importer: Python Project FAQ"
From Gcube Wiki
(→How to use the input file parameters) |
(→How to use the input file parameters) |
||
Line 27: | Line 27: | ||
== How to use the input file parameters == | == How to use the input file parameters == | ||
:For example we consider Phonebook algorithm: | :For example we consider Phonebook algorithm: | ||
− | [[Image:StatisticalAlgorithmsImporter_Phonebook0.png|thumb|center| | + | [[Image:StatisticalAlgorithmsImporter_Phonebook0.png|thumb|center|700px|Phonebook, SAI]] |
− | [[Image:StatisticalAlgorithmsImporter_Phonebook1.png|thumb|center| | + | [[Image:StatisticalAlgorithmsImporter_Phonebook1.png|thumb|center|700px|Phonebook, SAI]] |
− | [[Image:StatisticalAlgorithmsImporter_Phonebook2.png|thumb|center| | + | [[Image:StatisticalAlgorithmsImporter_Phonebook2.png|thumb|center|700px|Phonebook, SAI]] |
:DataMiner show the Phonebook algorithm in this way: | :DataMiner show the Phonebook algorithm in this way: | ||
− | [[Image:StatisticalAlgorithmsImporter_Phonebook3.png|thumb|center| | + | [[Image:StatisticalAlgorithmsImporter_Phonebook3.png|thumb|center|700px|Phonebook in DataMiner interface, SAI]] |
Revision as of 16:25, 10 January 2018
F.A.Q. of Statistical Algorithms Importer (SAI), here are common mistakes we have found in Python Project.
Matplotlib
Matplotlib require the $DISPLAY environment variable which means a running X server. DataMiner service do not allow a running X server session. So your code must be modified:
# # author Giancarlo Panichi # # Write file image.png # import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt import numpy as np .... plt.imshow(image) plt.savefig('image.png')
How to use the input file parameters
- For example we consider Phonebook algorithm:
- DataMiner show the Phonebook algorithm in this way:
- Python script code in sample:
# # author Giancarlo Panichi # # Phonebook # import sys import string true = 1 false = 0 def print_numbers(numbers): print "Telephone Numbers:" for x in numbers.keys(): value="Name: "+x+" Number: "+numbers[x] print value, def lookup_number(numbers,name): if numbers.has_key(name): return "For "+name+" the number is "+numbers[name] else: return "For "+name+" was not found" def load_numbers(numbers,filename): with open(filename,"r") as f: lines = f.readlines() lines for in_line in lines: [name,number] = string.split(in_line,",") numbers[name] = number def save_result(result,filename): with open(filename,"w") as f: f.write(result) phonebookFile=sys.argv[1] name=sys.argv[2] phone_list = {} load_numbers(phone_list,phonebookFile) print_numbers(phone_list) number=lookup_number(phone_list,name) print number save_result(number,"result.txt")
- phonebook.csv:
Giancarlo,0123456789 Gianpaolo,9876541234 Paolo,1231410414
- phonebook result with Giancarlo:
For Giancarlo the number is 0123456789
- Phonebook code: