User Tools

Site Tools



Export Scripts

A script is a file you can use to make report tables or other SOFA Statistics output. Scripts can be run using the free and open source Python programming language.

These tables will be saved to the output report location selected at the point when the script is exported.

Scripts enable a user to automate report making. It is possible to run SOFA reports without using the GUI (Graphical User Interface). Scripts can also be carefully hand-edited e.g. to change a report output location.

Clicking on Export generates a script to the script file displayed in the Script section of Make tables. If the file doesn't exist, SOFA makes one and adds the preliminary code. If a file exists, but is empty, SOFA puts some preliminary code in first and then the new exported script. If the file exists and is not empty, SOFA appends the script on the end.

Here is an example script:

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import codecs
import sys
import gettext
import numpy as np
gettext.install('sofa', './locale', unicode=False)
import my_globals as mg
import core_stats
import getdata
import output
import stats_output
import my_exceptions

fil ="/home/g/sofa/_internal/report.htm", "w", "utf-8")
css_fils=[u'/home/g/sofa/css/default.css', u'/home/g/sofa/css/lucid_spirals.css']
fil.write(output.get_html_hdr("Report(s)", css_fils, default_if_prob=True))

# end of script 'header'

# Script exported 14/06/2010 at 12:01 PM
con_dets = {u'SQLite': {u'sofa_db': {'database': u'/home/g/sofa/_internal/sofa_db'}}}
default_dbs = {u'MySQL': None, u'SQLite': u'sofa_db'}
default_tbls = {u'MySQL': None, u'SQLite': u'demo_tbl'}
dbe_resources = getdata.get_dbe_resources(dbe="SQLite", 
    con_dets=con_dets, default_dbs=default_dbs, default_tbls=default_tbls, 
    db="sofa_db", tbl="demo_tbl")
con = dbe_resources[mg.DBE_CON]
cur = dbe_resources[mg.DBE_CUR]
dbs = dbe_resources[mg.DBE_DBS]
db = dbe_resources[mg.DBE_DB]
tbls = dbe_resources[mg.DBE_TBLS]
tbl = dbe_resources[mg.DBE_TBL]
flds = dbe_resources[mg.DBE_FLDS]
idxs = dbe_resources[mg.DBE_IDXS]
has_unique = dbe_resources[mg.DBE_HAS_UNIQUE]
dp = 3
tbl_filt = u"""  """
sample_0 = core_stats.get_list(dbe=u"SQLite", cur=cur, tbl=u"demo_tbl",
    tbl_filt=tbl_filt, flds=flds, fld_measure=u"age", fld_filter=u"country", filter_val=1)
sample_1 = core_stats.get_list(dbe=u"SQLite", cur=cur, tbl=u"demo_tbl",
    tbl_filt=tbl_filt, flds=flds, fld_measure=u"age", fld_filter=u"country", filter_val=2)
sample_2 = core_stats.get_list(dbe=u"SQLite", cur=cur, tbl=u"demo_tbl",
    tbl_filt=tbl_filt, flds=flds, fld_measure=u"age", fld_filter=u"country", filter_val=3)
samples = [sample_0, sample_1, sample_2]
labels = [u'Japan', u'Italy', u'Germany']
label_a = u"Japan"
label_b = u"Germany"
label_avg = u"Age"
add_to_report = False
report_name = u"/home/g/sofa/reports/demo_report.htm"
p, F, dics, sswn, dfwn, mean_squ_wn, ssbn, dfbn, mean_squ_bn = \
    core_stats.anova(samples, labels, high=True)
anova_output = stats_output.anova_output(samples, F, p, dics, sswn, dfwn, mean_squ_wn, 
    ssbn, dfbn, mean_squ_bn, label_a, label_b, label_avg, add_to_report, report_name, dp,
    level=mg.OUTPUT_RESULTS_ONLY, css_idx=1, page_break_after=False)



To run a script, you can right click it and select something like Open in IDLE (it is assumed that IDLE was installed as part of the SOFA installation process or otherwise).

Once IDLE is open, you will have a windows containing the script file and another which is a console.

Inside the window containing the file you can press F5 for Run and you will see the result e.g. error messages, in the console window. There are other ways to run Python scripts but it can be useful to see the script you are running - not least of all so you can resolve any problems that arise.



help/export_scripts.txt · Last modified: 2010/08/26 17:02 (external edit)