#!/usr/bin/env python # xayagui """ BeginDate:200602017 CurrentRevisionDate:200602017 Development Version : core 001 Release Version: pre-release Author(s): Mishtu Banerjee, Tyler Mitchell, Dean Mikkelson Contact: mishtu@harmeny.com Copyright: The Authors License: Distributed under MIT License [http://opensource.org/licenses/mit-license.html] Environment: Programmed and tested under Python 2.3.3 on Windows 2000. Database Access: Psycopg and Postgres 7.4 Dependencies: CherryPy Python Interpreter and base libraries. Psycopg [website] Postgres [website] test X ============================================== XAYAgui_001 An Interface for Thinking with Data ============================================== XAYAgui is a Pythonic implementation of the Graph Abstraction Logic (GAL) design principles. GAL relationally models information as graphs (an old idea originating in modern logic) as a "little language" that can embedded or embellished. It provides a basis for modelling and querying data from complex systems. Data---> Information--> Knowledge (but wisdom is golden). GAL was inspired by Robert Ulanowicz's ecological network theory of Ascendency, Stan Salthe's developmental theory of Hierarchical Systems, and Charles Peirce's Existential Graphs (a visual method of doing logic). Hopefully beautiful ideas can lead to pragmatic working code ;-} ... Xayacore goes frominstances to ontologies,and points inbetween. One graph to rule them all! And some common sense to bind them ... Send bugs, fixes, suggestions to mishtu@harmeny.com (Thanks). USAGE EXAMPLE: (see examples under individual functions) ALGORITHMs: AlgorithmName -- Reference CODE SOURCES: Guido Code. [webref] Graphlib Code Pydot Code Graphpath Code Python Cookbook Djikstra's Algorithms in Python REFERENCES: Ascendency book. Salthe Hierarchy Book. Peirce Book (Reasoning and the Logic of Things) Graph Algorithms Reference Information Flow Book Foundations of Logic. Tools for Thought book """ # KNOWN BUGS # None Known at this point # UNITTESTS # Unittests are below fn/obj being tested # DESIGN CONTRACTS # Design Contract for each fn/obj is right after docstring #DOCTESTS # Used sparingly where they illustrate code above and beyond unittest # Import CherryPy web application framework import cherrypy import xayastats import os import webbrowser #Put GUI Body Here # ------------------- class XayaGUI: """ Class for all the xaya web access tools. """ # Header and Footer fns set up the top and bottom of a web page def header(self): content = ''' XAYA Tools ''' return content def footer(self): content = '''

Feedback

XAYA brought to you by the XAYA team

''' return content # The Index Fn sets up the first page launched by Cherry Py Server def index(self): """ This is the main index startup page. """ content = self.header() content += '''

Online data tools

Select File Path to Data

''' content += self.getFilePath() # Four FAILED ATTEMPTS TO GET AN IMAGE INTO CHERRY PY # Attempt 1 # content += "" DOES NOT WORK -- GET FUNNY TEXT, NOT IMAGE #Attempt 2 # image = open('/XAYA/devcore/xaya_small_web.gif') # content += image2.read() Also Does not work -- shows up as a broken link #Attempt 3 # image2 = open('/XAYA/devcore/XAYAgui/WebPageWithXayaGif.html') # content += '' # Again -- just a broken link #Attempt 4 # from cherrypy.lib.cptools import serveFile # image = open("/XAYA/devcore/xaya_small_web.gif") # content += serveFile(image,"image/gif") # Based on preview_image fn in Will's pemtools.py content += self.footer() return content def getFilePath(self): # ask for searchstring. content='''

File selector

What is the path?

''' return content # showFileResults sets up the second page; listbox content via showFunctionSelectList def showFileResults(self, uiDirectoryPath): content = self.header() content += '''

Online data tools

Select Dataset

''' path, file = self.getFilelist(uiDirectoryPath) content += "
" + self.showFileSelectList(path, file) # Enter Files List in Table content += " " + self.showFunctionSelectList() # Enter Functions List in Table #content += " " + self.showParametersSelectList(path, file) # Enter Parameters in a table content += "
" # Finish off table # content += self.showFileSelectList(path, file) # content += self.showFunctionSelectList(path, file) # content += self.showParametersSelectList(path, file) content += self.footer() return content # showFunctionSelectList adds listbox to 2nd page and sets up a SELECT list box # The selected file path is assigned to the var def showFileSelectList(self, path="", filelist=[]): select_list = '''

Files Available:

' select_list +='''

''' # We've Kept form Open so params passed to showFunctionSelectList # Removed from between

and Trile Quotes content = select_list return content def showFunctionSelectList(self): select_list = '''

Functions Available:

' select_list +='''

''' content = select_list return content def showParametersSelectList(self, path="", filelist=[]): select_list = '''

Parameters Available:

' select_list +='''

''' content = select_list return content # getFilelist is called as a helper fn in showFileResults that provides the # input list of files in a directory to showFunctionSelectList def getFilelist(self, path = "/"): """ List directory contents, and get friendly error messages if directories not found. """ try: # return os.listdir(path) filelist = os.listdir(path) except WindowsError: print "Sorry the directory path for safeListDir can not be found" print "Either the path leads to a directory that does not exist, or to a file name" print "The current working directory is" , os.getcwd() return [] return path, filelist def showDataset(self,uiAbsFilePath): content = self.header() content += '''

Online data tools

Show Dataset

''' # read in selected file dataset = xayastats.getDataset(uiAbsFilePath) # print as plain text #for line in dataset['DATA']: # content += str(dataset['DATA'][line][:]) + "
" # print as table content += "" for row in dataset['DATA']: content += "" for col in dataset['DATA'][row]: if row==0: content += "" content += "" content += "
" + uiAbsFilePath + "
" else: content += "" content += col if row==0: content += "" else: content += "
" content += self.footer() return content def showModDataset(self,uiAbsFilePath,uiFunctionList): content = self.header() content += '''

Online data tools

Show Dataset

''' # read in selected file data = xayastats.getDataset(uiAbsFilePath) #data = auditdataset(auditsamples=10,dataset=xayastats.getDataset(uiAbsFilePath)) function = uiFunctionList if function == 'auditDataset': data = xayastats.auditDataset(auditsamples=10,dataset=data) if function == 'sortDataset': data = xayastats.sortedDataset(dataset=data) if function == 'summarizeDataset': data = xayastats.summarizedDataset(dataset=data) # print as plain text #for line in dataset['DATA']: # content += str(dataset['DATA'][line][:]) + "
" # print as table content += "" for row in data['DATA']: content += "" for col in data['DATA'][row]: if row==0: content += "" content += "" content += "
" + uiAbsFilePath + "
" else: content += "" content += str(col) #must explicitly cast numerical data to strings if row==0: content += "" else: content += "
" content += self.footer() return content # Explicitly expose methods through web if using their exposed property index.exposed = True showFileResults.exposed = True showModDataset.exposed = True # ------------------- #Put GUI Body Here cherrypy.root = XayaGUI() if __name__ == '__main__': cherrypy.config.update(file = 'xayagui.conf') #cherrypy.server.start() cherrypy.server.start_with_callback(webbrowser.open,('http://localhost:8282/',),)