desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'@todo: docstring'
| def __repr__(self):
| repr = ''
for row in xrange((self.lastRow + 1)):
for col in xrange((self.lastCol + 1)):
posn = survey_MatrixElement.getPosn(row, col)
if (posn in self.matrix):
cell = self.matrix[posn]
data = str(cell)
else:
cell = None
... |
'@todo: docstring'
| def addCell(self, row, col, data, style, horizontal=0, vertical=0):
| cell = survey_MatrixElement(row, col, data, style)
if ((horizontal != 0) or (vertical != 0)):
cell.merge(horizontal, vertical)
try:
self.addElement(cell)
except Exception as msg:
current.log.error(msg)
return (((row + 1) + vertical), ((col + 1) + horizontal))
|
'Add an element to the matrix, checking that the position is unique.
@todo: parameter description'
| def addElement(self, element):
| posn = element.posn()
if (posn in self.matrix):
msg = ('Attempting to add data %s at posn %s. This is already taken with data %s' % (element, posn, self.matrix[posn]))
raise Exception(msg)
self.matrix[posn] = element
element.parents.append(self)
... |
'Return a list of all the styles used by all the elements joined
to the root element
@todo: parameter description'
| def joinedElementStyles(self, rootElement):
| styleList = []
row = rootElement.row
col = rootElement.col
for v in xrange((rootElement.mergeV + 1)):
for h in xrange((rootElement.mergeH + 1)):
newPosn = ('%s,%s' % ((row + v), (col + h)))
styleList += self.matrix[newPosn].styleList
return styleList
|
'This will set the joinedWith property to the posn of rootElement
for all the elements that rootElement joins with to make a single
large merged element.
@todo: parameter description'
| def joinElements(self, rootElement):
| row = rootElement.row
col = rootElement.col
posn = rootElement.posn()
for v in xrange((rootElement.mergeV + 1)):
for h in xrange((rootElement.mergeH + 1)):
newPosn = ('%s,%s' % ((row + v), (col + h)))
if (newPosn == posn):
continue
if (newPosn ... |
'Function to add a bounding box around the elements contained by
the elements (startrow, startcol) and (endrow, endcol)
This uses standard style names:
boxL, boxB, boxR, boxT
for Left, Bottom, Right and Top borders respectively
@todo: parameter description'
| def boxRange(self, startrow, startcol, endrow, endcol, width=1):
| for r in xrange(startrow, endrow):
posn = ('%s,%s' % (r, startcol))
if (posn in self.matrix):
self.matrix[posn].styleList.append(('boxL%s' % width))
else:
self.addElement(survey_MatrixElement(r, startcol, '', ('boxL%s' % width)))
posn = ('%s,%s' % (r, endcol))... |
'Constructor
@todo: parameter description'
| def __init__(self, row, col, data, style):
| self.row = row
self.col = col
self.text = data
self.mergeH = 0
self.mergeV = 0
self.joinedWith = None
self.parents = []
if isinstance(style, list):
self.styleList = style
else:
self.styleList = [style]
|
'@todo: docstring'
| def __repr__(self):
| return self.text
|
'@todo: docstring'
| def merge(self, horizontal=0, vertical=0):
| self.mergeH = horizontal
self.mergeV = vertical
for parent in self.parents:
parent.joinElements(self)
|
'Standard representation of the position
@todo: parameter description'
| @staticmethod
def getPosn(row, col):
| return ('%s,%s' % (row, col))
|
'Standard representation of the position'
| def posn(self):
| return self.getPosn(self.row, self.col)
|
'@todo: docstring'
| def nextX(self):
| return ((self.row + self.mergeH) + 1)
|
'@todo: docstring'
| def nextY(self):
| return ((self.col + self.mergeV) + 1)
|
'@todo: docstring'
| def merged(self):
| if ((self.mergeH > 0) or (self.mergeV > 0)):
return True
return False
|
'@todo: docstring'
| def joined(self):
| if (self.joinedWith is None):
return False
else:
return True
|
'Constructor
@todo: parameter description'
| def __init__(self, primaryMatrix, layout=None, widgetList=[], secondaryMatrix=None, langDict=None, addMethod=None):
| self.matrix = primaryMatrix
self.layout = layout
self.widgetList = widgetList
self.widgetsInList = []
self.answerMatrix = secondaryMatrix
self.langDict = langDict
if (addMethod is None):
self.addMethod = self.addData
else:
self.addMethod = addMethod
self.labelLeft = N... |
'@todo: docstring'
| def processRule(self, rules, row, col, matrix):
| startcol = col
endcol = col
endrow = row
action = 'rows'
self.widgetsInList = []
for element in rules:
row = endrow
col = startcol
self.nextrow = row
self.nextcol = col
if isinstance(element, list):
(endrow, endcol) = self.processList(element, ... |
'@todo: docstring'
| def processList(self, rules, row, col, matrix, action='rows'):
| startcol = col
startrow = row
endcol = col
endrow = row
for element in rules:
if (action == 'rows'):
row = startrow
col = endcol
elif (action == 'columns'):
row = endrow
col = startcol
if isinstance(element, list):
(... |
'@todo: docstring'
| def processDict(self, rules, parent, row, col, matrix, action='rows'):
| startcol = col
startrow = row
endcol = col
endrow = row
if ('boxOpen' in rules):
return self.processBox(rules, row, col, matrix, action)
if ('heading' in rules):
text = rules['heading']
if (len(parent) == 1):
width = (min(len(text), matrix.lastCol) + 1)
... |
'@todo: docstring'
| def processBox(self, rules, row, col, matrix, action='rows'):
| startcol = col
startrow = row
endcol = col
endrow = row
headingrow = row
self.addToLayout(startrow, startcol, andThenPostpone=True)
if ('heading' in rules):
row += 1
if ('data' in rules):
self.boxOpen = True
value = rules['data']
(endrow, endcol) = self.pr... |
'@todo: docstring'
| def addToLayout(self, startrow, startcol, andThenPostpone=None, endPostpone=None):
| if (endPostpone != None):
self.postponeLayoutUpdate = (not endPostpone)
if ((not self.postponeLayoutUpdate) and (self.layout != None) and ((startrow != self.nextrow) or (startcol != self.nextcol))):
if (self.widgetsInList != []):
self.layout.addTempBlock((startrow, startcol), (self.n... |
'@todo: docstring'
| def addArea(self, element, row, col):
| try:
widgetObj = self.widgetList[element]
except:
_debug(('Unable to find element %s in the template' % element))
return self.matrix.addCell(row, col, '', [])
widgetObj.startPosn = (col, row)
if self.labelLeft:
widgetObj.labelLeft = (self.labelLeft ==... |
'@todo: docstring'
| def addLabel(self, label, row, col, width=11, height=None, style='styleSubHeader'):
| cell = survey_MatrixElement(row, col, label, style=style)
if (height is None):
height = ((len(label) / (2 * width)) + 1)
cell.merge(horizontal=(width - 1), vertical=(height - 1))
try:
self.matrix.addElement(cell)
except Exception as msg:
current.log.error(msg)
return ... |
'@todo: docstring'
| def addData(self, element, row, col):
| try:
widgetObj = self.widgetList[element]
except:
_debug(('Unable to find element %s in the template' % element))
return self.matrix.addCell(row, col, '', [])
widgetObj.startPosn = (col, row)
self.widgetsInList.append(widgetObj)
if self.labelLeft:
... |
'This will store the question id in self.id,
the question data in self.question, and
the metadata for this specific question in self.qstn_metadata
It will only get the data from the db if it hasn\'t already been
retrieved, or if the update flag is True'
| def _store_metadata(self, qstn_id=None, update=False):
| if (qstn_id is not None):
if (self.id != qstn_id):
self.id = qstn_id
update = True
if (self.id is None):
self.question = None
self.qstn_metadata = {}
return
if ((self.question is None) or update):
db = current.db
question = db((self.qta... |
'This will return a single metadata value held by the widget'
| def get(self, value, default=None):
| if (value in self.qstn_metadata):
return self.qstn_metadata[value]
else:
return default
|
'This will store a single metadata value'
| def set(self, value, data):
| self.qstn_metadata[value] = data
|
'Return the value of the answer for this question'
| def getAnswer(self):
| if ('answer' in self.question):
answer = self.question.answer
else:
answer = ''
return answer
|
'function to format the answer, which can be passed in'
| def repr(self, value=None):
| if (value is None):
value = self.getAnswer()
return value
|
'This will return a value held by the widget
The value can be held in different locations
1) In the widget itself:
2) In the database: table.survey_complete'
| def loadAnswer(self, complete_id, question_id, forceDB=False):
| value = None
self._store_metadata(question_id)
if (('answer' in self.question) and (self.question.complete_id == complete_id) and (forceDB == False)):
value = self.question.answer
else:
table = self.atable
query = ((table.complete_id == complete_id) & (table.question_id == questi... |
'This method set\'s up the variables that will be used by all
display methods of fields for the question type.
It uses the metadata to define the look of the field'
| def initDisplay(self, **attr):
| if ('question_id' in attr):
self.id = attr['question_id']
if (self.id is None):
raise Exception('Need to specify the question_id for this QuestionType')
qstn_id = self.id
self._store_metadata(qstn_id)
attr['_name'] = self.question.code
self.attr = attr
|
'This displays the widget on a web form. It uses the layout
function to control how the widget is displayed'
| def display(self, **attr):
| self.initDisplay(**attr)
value = self.getAnswer()
input = self.webwidget.widget(self.field, value, **self.attr)
return self.layout(self.question.name, input, **attr)
|
'This lays the label widget that is passed in on the screen.
Currently it has a single default layout mechanism but in the
future it will be possible to add more which will be controlled
vis the attr passed into display and stored in self.attr'
| def layout(self, label, widget, **attr):
| if ('display' in attr):
display = attr['display']
else:
display = 'Default'
if (display == 'Default'):
elements = []
elements.append(TR(TH(label), TD(widget), _class='survey_question'))
return TAG[''](elements)
elif (display == 'Control Only'):
return T... |
'Method to format the value that has just been put into the database'
| def onaccept(self, value):
| return value
|
'Display the type in a DIV for displaying on the screen'
| def type_represent(self):
| return DIV(self.typeDescription, _class='surveyWidgetType')
|
'Return the real database table type for this question
This assumes that the value is valid'
| def db_type(self):
| return 'string'
|
'Function to translate the question using the dictionary passed in'
| def _Tquestion(self, langDict):
| return survey_T(self.question['name'], langDict)
|
'Function to return the size of the label, in terms of merged
MatrixElements'
| def getLabelSize(self, maxWidth=20):
| labelSize = (0, 0)
if self.label:
labelWidth = (maxWidth / 2)
if (not self.labelLeft):
labelWidth = (self.xlsWidgetSize[0] + 1)
_TQstn = self._Tquestion(self.langDict)
labelSize = (labelWidth, ((len(_TQstn) / ((4 * labelWidth) / 3)) + 1))
return labelSize
|
'Function to return the size of the input control, in terms of merged
MatrixElements'
| def getWidgetSize(self, maxWidth=20):
| return ((self.xlsWidgetSize[0] + 1), (self.xlsWidgetSize[1] + 1))
|
'Function to return the size of the widget'
| def getMatrixSize(self):
| labelSize = self.getLabelSize()
widgetSize = self.getWidgetSize()
if self.labelLeft:
return ((max(labelSize[1], widgetSize[1]) + self.xlsMargin[1]), ((labelSize[0] + widgetSize[0]) + self.xlsMargin[0]))
else:
return (((labelSize[1] + widgetSize[1]) + self.xlsMargin[1]), (max(labelSize[0]... |
'Function to write out basic details to the matrix object'
| def writeToMatrix(self, matrix, row, col, langDict={}, answerMatrix=None):
| self._store_metadata()
startrow = row
startcol = col
mergeLH = 0
mergeLV = 0
height = 0
width = 0
if self.label:
_TQstn = self._Tquestion(langDict)
cell = survey_MatrixElement(row, col, _TQstn, style='styleSubHeader')
(width, height) = self.getLabelSize()
... |
'Function to write the basic question details to a rtf document.
The basic details will be written to Cell objects that can be
added to a row in a table object.
@param ss: StyleSheet object
@param langDict: Dictionary of languages
@param full_name: Question name(label)
@param paragraph: Add paragraph from S3QuestionTyp... | @staticmethod
def _writeToRTF(ss, langDict, full_name, paragraph=None, para_list=[], question_name=''):
| from gluon.contrib.pyrtf.Elements import Paragraph, Cell, B
from gluon.contrib.pyrtf.PropertySets import BorderPS, FramePS
thin_edge = BorderPS(width=20, style=BorderPS.SINGLE)
thin_frame = FramePS(thin_edge, thin_edge, thin_edge, thin_edge)
line = []
if question_name:
p = Paragraph(ss.P... |
'Wrapper function for _writeToRTF
@param ss: StyleSheet object
@param langDict: Dictionary of languages'
| def writeQuestionToRTF(self, ss, langDict):
| full_name = self.fullName()
return self._writeToRTF(ss, langDict, full_name)
|
'This will validate the data passed in to the widget
NOTE: Not currently used but will be used when the UI supports the
validation of data entered in to the web form'
| def validate(self, valueList, qstn_id):
| if (len(valueList) == 0):
return self.ANSWER_MISSING
data = value(valueList, 0)
if (data is None):
return self.ANSWER_MISSING
length = self.get('Length')
if ((length is not None) and (length(data) > length)):
return ANSWER_PARTLY_VALID
return self.ANSWER_VALID
|
'Create the input fields for the metadata for the QuestionType
NOTE: Not currently used but will be used when the UI supports the
creation of the template and specifically the questions in
the template'
| def metadata(self, **attr):
| if ('question_id' in attr):
self._store_metadata(attr['question_id'])
elements = []
for fieldname in self.metalist:
value = self.get(fieldname, '')
input = StringWidget.widget(self.field, value, **attr)
elements.append(TR(TD(fieldname), TD(input)))
return TAG[''](elements... |
'Function to write the basic question details to a rtf document.
The basic details will be written to Cell objects that can be
added to a row in a table object.
@param ss: StyleSheet object
@param langDict: Dictionary of languages'
| def writeQuestionToRTF(self, ss, langDict):
| from gluon.contrib.pyrtf.Elements import Paragraph
paragraph = Paragraph(ss.ParagraphStyles.Normal)
full_name = self.fullName()
return self._writeToRTF(ss, langDict, full_name, paragraph=paragraph)
|
'Method to format the value that has just been put on the database'
| def onaccept(self, value):
| return str(self.formattedAnswer(value))
|
'Return the real database table type for this question
This assumes that the value is valid'
| def db_type(self):
| format = self.get('Format', 'n')
if (format == 'n'):
return 'integer'
else:
return 'double'
|
'This will validate the data passed in to the widget'
| def validate(self, valueList, qstn_id):
| result = S3QuestionTypeAbstractWidget.validate(self, valueList)
if (result != ANSWER_VALID):
return result
format = self.get('Format')
data = value(valueList, 0)
if (format != None):
try:
self.formattedValue(data, format)
return self.ANSWER_VALID
excep... |
'This will take a string and do it\'s best to return a Date object
It will try the following in order
* Convert using the ISO format:
* look for a month in words a 4 digit year and a day (1 or 2 digits)
* a year and month that matches the date now and NOT a future date
* a year that matches the current date and the pre... | def formattedAnswer(self, data):
| rawDate = data
date = None
try:
isoDate = ''
addHyphen = False
for char in rawDate:
if char.isdigit:
if ((addHyphen == True) and (isoDate != '')):
isoDate += '-'
isoDate += char
addHyphen = False
... |
'This will validate the data passed in to the widget'
| def validate(self, valueList, qstn_id):
| result = S3QuestionTypeAbstractWidget.validate(self, valueList)
if (result != ANSWER_VALID):
return result
format = self.get('format')
data = value(valueList, 0)
if (format != None):
try:
self.formattedValue(data, format)
return self.ANSWER_VALID
excep... |
'Function to return the size of the input control'
| def getWidgetSize(self, maxWidth=20):
| instHeight = (1 + (len(self.selectionInstructions) / maxWidth))
if self.singleRow:
widgetHeight = 1
else:
widgetHeight = len(self.getList())
return ((maxWidth / 2), (instHeight + widgetHeight))
|
'Function to write out basic details to the matrix object'
| def writeToMatrix(self, matrix, row, col, langDict={}, answerMatrix=None):
| self._store_metadata()
startrow = row
startcol = col
mergeLH = 0
mergeLV = 0
maxWidth = 20
endrow = row
endcol = col
lwidth = 10
lheight = 1
iheight = 0
if self.label:
_TQstn = self._Tquestion(langDict)
cell = survey_MatrixElement(row, col, _TQstn, style='... |
'Function to write the basic question details to a rtf document.
The basic details will be written to Cell objects that can be
added to a row in a table object.
@param ss: StyleSheet object
@param langDict: Dictionary of languages'
| def writeQuestionToRTF(self, ss, langDict):
| para_list = self.getList()
full_name = self.fullName()
return self._writeToRTF(ss, langDict, full_name, para_list=para_list)
|
'This will validate the data passed in to the widget'
| def validate(self, valueList, qstn_id):
| if (len(valueList) == 0):
return self.ANSWER_MISSING
data = valueList[0]
if (data is None):
return self.ANSWER_MISSING
self._store_metadata(qstn_id)
if (data in self.getList()):
return self.ANSWER_VALID
else:
return self.ANSWER_VALID
return self.ANSWER_INVALID... |
'@todo: docstring'
| def display(self, **attr):
| S3QuestionTypeAbstractWidget.initDisplay(self, **attr)
self.field.requires = IS_IN_SET(self.getList())
value = self.getAnswer()
valueList = json2list(value)
self.field.name = self.question.code
input = CheckboxesWidget.widget(self.field, valueList, **self.attr)
self.field.name = 'value'
... |
'This displays the widget on a web form. It uses the layout
function to control how the widget is displayed'
| def display(self, **attr):
| return S3QuestionTypeAbstractWidget.display(self, **attr)
|
'Return the location record from the database'
| def getLocationRecord(self, complete_id, location):
| record = Storage()
if (location != None):
gtable = current.s3db.gis_location
query = (gtable.name == location)
record = current.db(query).select(gtable.name, gtable.lat, gtable.lon)
record.complete_id = complete_id
record.key = location
if (len(record.records) == ... |
'Method to format the value that has just been put on the database'
| def onaccept(self, value):
| return value
|
'If the answer is stored as a JSON value return the data as a map
If it is not valid JSON then an exception will be raised,
and must be handled by the calling function'
| def getAnswerListFromJSON(self, answer):
| answerList = json2py(answer)
return answerList
|
'This will validate the data passed in to the widget'
| def validate(self, valueList, qstn_id):
| result = S3QuestionTypeAbstractWidget.validate(self, valueList)
if (result != ANSWER_VALID):
return result
length = self.get('length', 10)
format = self.get('format')
data = value(valueList, 0)
if (format != None):
try:
self.formattedValue(data, format)
re... |
'Method to format the value that has just been put on the database'
| def onaccept(self, value):
| return self.realWidget().onaccept(value)
|
'Return the real database table type for this question
This assumes that the value is valid'
| def db_type(self):
| return self.realWidget().db_type()
|
'This will validate the data passed in to the widget'
| def validate(self, valueList, qstn_id):
| qtype = self.get('Type')
realWidget = survey_question_type[qtype]()
return realWidget.validate(valueList, qstn_id)
|
'Function to write out basic details to the matrix object'
| def writeToMatrix(self, matrix, row, col, langDict={}, answerMatrix=None):
| self._store_metadata()
self.getMetaData()
startrow = row
startcol = col
endrow = row
endcol = col
maxWidth = 20
labelWidth = (maxWidth / 2)
codeNum = self.qstnNo
row += 1
needHeading = True
subtitle = survey_T(self.subtitle, self.langDict)
cell = survey_MatrixElement(... |
'Function to write the basic question details to a rtf document.
This will just display the grid name, following this will be the
grid child objects.
@param ss: StyleSheet object
@param langDict: Dictionary of languages'
| def writeQuestionToRTF(self, ss, langDict):
| question_name = self.question.name
full_name = self.fullName()
return self._writeToRTF(ss, langDict, full_name, question_name=question_name)
|
'Return the real database table type for this question
This assumes that the value is valid'
| def db_type(self):
| return self.realWidget().db_type()
|
'Dummy function that doesn\'t write anything to the matrix,
because it is handled by the Grid question type'
| def writeToMatrix(self, matrix, row, col, langDict={}, answerMatrix=None, style={}):
| return (row, col)
|
'Function to write the basic question details to a rtf document.
The basic details will be written to Cell objects that can be
added to a row in a table object.
@param ss: StyleSheet object
@param langDict: Dictionary of languages'
| def writeQuestionToRTF(self, ss, langDict):
| return self.realWidget().writeQuestionToRTF(ss, langDict)
|
'Constructor
@todo: do not use lists or dicts as parameter defaults!
@todo: parameter description'
| def __init__(self, range=[(-1), (-0.5), 0, 0.5, 1], colour={(-1): '#888888', 0: '#000080', 1: '#008000', 2: '#FFFF00', 3: '#FFA500', 4: '#FF0000', 5: '#880088'}, opacity={(-1): 0.5, 0: 0.6, 1: 0.6, 2: 0.7, 3: 0.7, 4: 0.8, 5: 0.8}, image={(-1): 'grey', 0: 'blue', 1: 'green', 2: 'yellow', 3: 'orange', 4: 'red', 5: 'purpl... | self.range = range
self.colour = colour
self.opacity = opacity
self.image = image
self.description = desc
|
'@todo: docstring'
| def imageURL(self, app, key):
| filename = self.image[key]
dot_url = ('/%s/static/img/survey/%s-dot.png' % (app, filename))
image = IMG(_src=dot_url, _alt=current.T(filename), _height=12, _width=12)
return image
|
'@todo: docstring'
| def desc(self, key):
| return current.T(self.description[key])
|
'@todo: docstring'
| def rangeText(self, key, pBand):
| if (key == (-1)):
return ''
elif (key == 0):
return (current.T('At or below %s') % pBand[1])
elif (key == (len(pBand) - 1)):
return (current.T('Above %s') % pBand[(len(pBand) - 1)])
else:
return ('%s - %s' % (pBand[key], pBand[(key + 1)]))
|
'Constructor
@todo: parameter description'
| def __init__(self, type, question_id, answerList):
| self.question_id = question_id
self.answerList = answerList
self.valueList = []
self.result = []
self.type = type
self.qstnWidget = survey_question_type[type](question_id=question_id)
self.priorityGroup = 'zero'
self.priorityGroups = {'default': [(-1), (-0.5), 0, 0.5, 1], 'standard': [(-... |
'Used to validate a single answer
@todo: parameter description
@todo: raise exception if abstract and override is mandatory'
| def valid(self, answer):
| return True
|
'Used to modify the answer from its raw text format.
Where necessary, this function will be overridden.
@todo: parameter description
@todo: raise exception if abstract and override is mandatory'
| def castRawAnswer(self, complete_id, answer):
| return answer
|
'Perform basic analysis of the answer set.
Where necessary, this function will be overridden.
@todo: parameter description
@todo: raise exception if abstract and override is mandatory'
| def basicResults(self):
| pass
|
'This will display a button which when pressed will display a chart
When a chart is not appropriate then the subclass will override this
function with a null function.
@todo: parameter description
@todo: make a class property rather than overriding in subclasses'
| def chartButton(self, series_id):
| if (len(self.valueList) == 0):
return None
if (series_id is None):
return None
src = URL(f='completed_chart', vars={'question_id': self.question_id, 'series_id': series_id, 'type': self.type})
link = A(current.T('Chart'), _href=src, _target='blank', _class='action-btn')
return DIV(li... |
'Get chart name for series_id
@todo: parameter description'
| def getChartName(self, series_id):
| import hashlib
h = hashlib.sha256()
h.update(self.qstnWidget.question.code)
encoded_part = h.hexdigest()
chartName = ('survey_series_%s_%s' % (series_id, encoded_part))
return chartName
|
'This function will draw the chart using the answer set.
This function must be overridden by the subclass.
@todo: parameter description
@todo: raise NotImplementedException if override is mandatory'
| def drawChart(self, series_id, output=None, data=None, label=None, xLabel=None, yLabel=None):
| msg = ('Programming Error: No chart for %sWidget' % self.type)
output = StringIO()
output.write(msg)
current.response.body = output
|
'Calculate a summary of basic data.
Where necessary, this function will be overridden.'
| def summary(self):
| self.result = []
return self.count()
|
'Create a basic count of the data set.
Where necessary, this function will be overridden.'
| def count(self):
| self.result.append(([current.T('Replies')], len(self.answerList)))
return self.format()
|
'This function will take the results and present them in a
HTML table
@todo: rename into "formatted"'
| def format(self):
| table = TABLE()
for (key, value) in self.result:
table.append(TR(TD(B(key)), TD(value)))
return table
|
'Calculate the number of occurrences of each value'
| def uniqueCount(self):
| _map = {}
for answer in self.valueList:
if (answer in _map):
_map[answer] += 1
else:
_map[answer] = 1
return _map
|
'Method to group the answers by the categories passed in
The categories will belong to another question.
For example the categories might be an option question which has
responses from High, Medium and Low. So all the responses that
correspond to the High category will go into one group, the Medium
into a second group ... | def groupData(self, groupAnswer):
| grouped = {}
answers = {}
for answer in self.answerList:
answers[answer['complete_id']] = answer['value']
for ganswer in groupAnswer:
gcode = ganswer['complete_id']
greply = ganswer['value']
if (gcode in answers):
value = answers[gcode]
if (greply ... |
'Filter the data within the groups by the filter type
@todo: indicate whether this is meant to be overwritten by
subclass (if not: remove it!)
@todo: parameter description'
| def filter(self, filterType, groupedData):
| return groupedData
|
'Split the data set by the groups
@todo: parameter description'
| def splitGroupedData(self, groupedData):
| keys = []
values = []
for (key, value) in groupedData.items():
keys.append(key)
values.append(value)
return (keys, values)
|
'@todo: docstring'
| def castRawAnswer(self, complete_id, answer):
| try:
return float(answer)
except ValueError:
return None
|
'@todo: docstring'
| def summary(self):
| T = current.T
widget = S3QuestionTypeNumericWidget()
fmt = widget.formattedAnswer
append = self.result.append
if self.sum:
append(([T('Total')], fmt(self.sum)))
if self.average:
append(([T('Average')], fmt(self.average)))
if self.max:
append(([T('Maximum')], fmt(self.... |
'@todo: docstring'
| def count(self):
| T = current.T
append = self.result.append
append((T('Replies'), len(self.answerList)))
append((T('Valid'), self.cnt))
return self.format()
|
'@todo: docstring'
| def basicResults(self):
| self.cnt = 0
if (len(self.valueList) == 0):
self.sum = None
self.average = None
self.max = None
self.min = None
return
self.sum = 0
self.max = self.valueList[0]
self.min = self.valueList[0]
for answer in self.valueList:
self.cnt += 1
self.s... |
'@todo: docstring'
| def advancedResults(self):
| try:
from numpy import array
except:
current.log.error('ERROR: S3Survey requires numpy library installed.')
array = array(self.valueList)
self.std = array.std()
self.mean = array.mean()
self.zscore = {}
for answer in self.answerList:
complete_id = answe... |
'@todo: docstring'
| def priority(self, complete_id, priorityObj):
| priorityList = priorityObj.range
priority = 0
try:
zscore = self.zscore[complete_id]
for limit in priorityList:
if (zscore <= limit):
return priority
priority += 1
return priority
except:
return (-1)
|
'@todo: docstring'
| def priorityBand(self, priorityObj):
| priorityList = priorityObj.range
band = ['']
cnt = 0
for limit in priorityList:
value = int((self.mean + (limit * self.std)))
if (value < 0):
value = 0
priorityList[cnt] = ((- self.mean) / self.std)
band.append(value)
cnt += 1
return band
|
'@todo: docstring'
| def chartButton(self, series_id):
| if (self.qstnWidget.get('Format', 'n') != 'n'):
return None
if (len(self.valueList) < self.histCutoff):
return None
return S3AbstractAnalysis.chartButton(self, series_id)
|
'@todo: docstring'
| def drawChart(self, series_id, output='xml', data=None, label=None, xLabel=None, yLabel=None):
| chartFile = self.getChartName(series_id)
cached = S3Chart.getCachedFile(chartFile)
if cached:
return cached
chart = S3Chart(path=chartFile)
chart.asInt = True
if (data is None):
chart.survey_hist(self.qstnWidget.question.name, self.valueList, 10, 0, self.max, xlabel=self.qstnWidg... |
'@todo: docstring'
| def filter(self, filterType, groupedData):
| filteredData = {}
if (filterType == 'Sum'):
for (key, valueList) in groupedData.items():
total = 0
for value in valueList:
try:
total += self.castRawAnswer(None, value)
except:
pass
filteredData[k... |
'@todo: docstring'
| def summary(self):
| T = current.T
append = self.result.append
for (key, value) in self.listp.items():
append((T(key), value))
return self.format()
|
'@todo: docstring'
| def basicResults(self):
| cnt = 0
slist = {}
for answer in self.valueList:
cnt += 1
if (answer in slist):
slist[answer] += 1
else:
slist[answer] = 1
self.cnt = cnt
self.list = slist
listp = {}
if (cnt != 0):
for (key, value) in slist.items():
listp[k... |
'@todo: docstring'
| def drawChart(self, series_id, output='xml', data=None, label=None, xLabel=None, yLabel=None):
| chartFile = self.getChartName(series_id)
cached = S3Chart.getCachedFile(chartFile)
if cached:
return cached
chart = S3Chart(path=chartFile)
data = []
label = []
for (key, value) in self.list.items():
data.append(value)
label.append(key)
chart.survey_pie(self.qstnW... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.