#!/usr/bin/env python3
#=====================================================================================
# Get numeric data from sys.arg
# if not supplied, use a hardcoded array
#=====================================================================================
import sys                                          #sys module to accept arguments
sys.path.insert(0,'/home/s/sultans/web/python/demo/oo/zAnalytics')
from Analytics import Analytics                     #import the Analytics class

print("Content-Type: text/html \n")                  #http header with newline char (required for web) 

in_array = ["Some data", 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 2.2]      #hardcoded array

if (len(sys.argv) > 1):                             #if argument are provided
    in_array = sys.argv[1:len(sys.argv)]            #eliminate the first arg (script name)

    
#=====================================================================================
# display: Display the 2 dimensional data array
#=====================================================================================
def display(array):

    print("\nINPUT DATA...")
     
    for value in array:                               #loop thru the array
        print(value, "\t",end='')                     #print each value 
    print()

#=====================================================================================
# compute: Compute and print
#=====================================================================================
def compute(array):

    print("\nCOMPUTATION...")

    array = Analytics.normalize(array)              #clean up the array, and make it numeric
    obj   = Analytics(array)                        #Create an Analytics object

    print(obj)                                      #print entire analytics   


#=====================================================================================
# main code
#=====================================================================================

display(in_array)                                   #display formatted
compute(in_array)                                   #compute analytics



#=== link to see the python code =================================================
import os, sys
sys.path.insert(0,'/home/s/sultans/web/python/demo')
import zCode                          #import func to display the Python code
filename = os.path.abspath(__file__)  #get absolute file name 
zCode.display(filename)               #call it
#=================================================================================