Beispiel #1
0
def test_ma_schools():
  with session(MASCHOOLS_DIR):
    msglimit = None if pytest.config.option.verbose else 1000
    vn.run_and_verify_notebook(
      os.path.join(MASCHOOLS_DIR, "MASchoolDistricts"),
      msglimit=msglimit,
      required=[('schools2.quick_explore_vars\(\[',
                 [vn.allow_warns('matplotlib.*backend'),
                  vn.allow_warns('VisibleDeprecationWarning')]),
                ('ESTIMATE DEPENDENCE PROBABILITY',
                 [vn.assert_has_png(), vn.allow_warns('FutureWarning'),
                  vn.allow_warns('VisibleDeprecationWarning')]),
                ('schools0.quick_describe_variables()',
                 [r'categorical', vn.allow_warns(
                     'Invalid value encountered in percentile')]),
                ('schools1.quick_describe_variables()',
                 [r'categorical', vn.allow_warns(
                     'Invalid value encountered in percentile')]),
                # Once solved, this will not contain categorical, but as
                # set up to be solved, it does:
                ('schools2.quick_describe_variables()',
                 [r'categorical', vn.allow_warns(
                     'Invalid value encountered in percentile')]),
                # As set up, this should have "cannot convert" messages,
                # Not once it's solved though.
                ('df.applymap', [vn.assert_stream_matches('Cannot convert')]),
                (r'schools2.quick_explore_vars',
                 [vn.allow_warns('VisibleDeprecationWarning')])
                ])
Beispiel #2
0
def test_index():
    os.chdir(INDEX_DIR)
    with session(INDEX_DIR):
        run_and_verify_notebook(os.path.join(INDEX_DIR, "Index"))
        optfile = os.path.join(INDEX_DIR, OPTFILE)
        assert os.path.exists(optfile)
        if 'DEBUG_TESTS' not in os.environ:
            with open(optfile, 'r') as opt:
                assert " <>\n" == opt.read()
Beispiel #3
0
def test_index():
  os.chdir(INDEX_DIR)
  with session(INDEX_DIR):
    run_and_verify_notebook(os.path.join(INDEX_DIR, "Index"))
    optfile = os.path.join(INDEX_DIR, OPTFILE)
    assert os.path.exists(optfile)
    if 'DEBUG_TESTS' not in os.environ:
      with open(optfile, 'r') as opt:
        assert " <>\n" == opt.read()
Beispiel #4
0
	def curGroup(self, name):
		id = util.session('current_user', identity.current.user.id)		
		user = User.get(id)
		groups = [g.group_name for g in user.groups]
		
		if name in groups:
			return {'checked':'checked'}
		else:
			return {'checked':None}
Beispiel #5
0
	def curProg(self, programid):
		user_id = int(util.session('current_user', identity.current.user.id))
		
		if int(user_id) == 0:
			return {'selected':None}
		
		if User.get(user_id).programID == int(programid):
			return {'selected':'selected'}
		return {'selected':None}
Beispiel #6
0
	def index(self, id=None, message=""):
		
		id = util.session('current_user', identity.current.user.id, id)
		if int(id) == 0:
			raise redirect('/userprofile/createUser?message=message')
		
		user = User.get(id)
		groups = [g.group_name for g in user.groups]
		programlist = Program.select()
		
		return dict(user=user, programlist=programlist, curProg=self.curProg, curGroup=self.curGroup, groups=groups, message=message)
Beispiel #7
0
def test_satellites():
    with session(SATELLITES_DIR):
        if ("DEBUG_TESTS" not in os.environ or not os.path.exists(
                os.path.join(SATELLITES_DIR, "satellites.bdb"))):
            remove_bdb_files(SATELLITES_DIR)  # Just in case.
            rebuild_bdb(SATELLITES_DIR)
        msglimit = None if pytest.config.option.verbose else 1000
        run_and_verify_notebook(os.path.join(SATELLITES_DIR, "Satellites"),
                                exhaustive=EXPECTED,
                                msglimit=msglimit)
        if "DEBUG_TESTS" not in os.environ:
            remove_bdb_files(SATELLITES_DIR)
Beispiel #8
0
	def index(self, id=None):
		
		id = util.session('current_child', 0, id)
		
		if id == 0:		# no id given
			raise redirect("/")
		
		try:
			current_child = Child.get(id)
		except SQLObjectNotFound:	# Child with given id does not exist
			raise redirect("/")
		
		return dict(child=current_child, shaded=util.shaded)
def test_satellites():
  with session(SATELLITES_DIR):
    if ("DEBUG_TESTS" not in os.environ or
        not os.path.exists(os.path.join(SATELLITES_DIR, "satellites.bdb"))):
      remove_bdb_files(SATELLITES_DIR) # Just in case.
      rebuild_bdb(SATELLITES_DIR)
    msglimit = None if pytest.config.option.verbose else 1000
    run_and_verify_notebook(
      os.path.join(SATELLITES_DIR, "Satellites"),
      exhaustive=EXPECTED,
      msglimit=msglimit)
    if "DEBUG_TESTS" not in os.environ:
      remove_bdb_files(SATELLITES_DIR)
Beispiel #10
0
def test_ma_schools():
  with session(PARENT_DIR):
    msglimit = None if pytest.config.option.verbose else 1000
    vn.run_and_verify_notebook(
      os.path.join(PARENT_DIR, "querying-and-plotting"),
      msglimit=msglimit,
      required=[('pairplot_vars\(', [vn.assert_has_png()]),
                ('pairplot\(', [vn.assert_has_png()]),
                ('barplot\(', [vn.assert_has_png()]),
                ('histogram\(', [vn.assert_has_png()]),
                ('heatmap\(', [vn.assert_has_png()]),
                ],
      warnings_are_errors=False)
Beispiel #11
0
	def validateUser(self, **kw):
		
		username = kw['username']
		password = kw['password']
		retype = kw['retype']
		
		program = util.session('current_program', identity.current.user.programID)
		
		if password != retype:
			raise redirect("/userprofile?id=0&message=Password+and+retype+do+not+match")
		
		try:
			user = User(user_name=username, password=password, programID=program)
		except:
			raise redirect("/userprofile?id=0&message=Username+already+taken")
		
		#return "SUCCESS"
		raise redirect("/userprofile?id=" + str(user.id))
Beispiel #12
0
    def index(self, program=None):
        program = util.session("current_program", identity.current.user.programID, program)
        if identity.in_group("global_admin") and int(program) == 0:
            userlist = User.select()
            program = identity.current.user.programID
        elif int(program) == 0:
            program = identity.current.user.programID
            userlist = User.selectBy(programID=program)
        else:
            userlist = User.selectBy(programID=program)
        programlist = Program.select()

        return dict(
            program=Program.get(program),
            programlist=programlist,
            curProg=self.curProg,
            userlist=userlist,
            shaded=util.shaded,
        )
Beispiel #13
0
 def curProg(self, programid):
     if int(util.session("current_program", identity.current.user.programID)) == int(programid):
         return {"selected": "selected"}
     return {"selected": None}
Beispiel #14
0
	def index1(self, id=None, category=None, osep='None', print_area='false'):
		if identity.current.user.basketmode:
			raise redirect(url("index2",id=id,category=category,osep=osep,print_area=print_area))
		osep = True
	
		if print_area == 'true':
			print_area = True
		else:
			print_area = False
		
		id = util.session('current_assessment', 0, id)
		category = util.session('current_category', 'Fine Motor', category)
		osep = util.session('osep', False, osep)
		child = util.session('current_child', 0)
		
		if id == 0:		# no id given
			raise redirect("/")
		
		try:
			current_assessment = Assessment.get(id)
		except SQLObjectNotFound:	# Child with given id does not exist
			raise redirect("/")

		current_child = current_assessment.child
		all_assessments = current_child.assessments
		
		sorted_assessments = Assessment.select(AND(Assessment.q.childID==current_assessment.childID,
												   Assessment.q.id!=id,
												   Assessment.q.level==current_assessment.level), orderBy='-dateEntered')
		old = list(sorted_assessments[:7])
		
		if osep:
			criteria = Criterion.selectBy(category=category, level=current_assessment.level, osep=True)
		else:
			criteria = Criterion.selectBy(category=category, level=current_assessment.level)
			
		criteria = criteria.orderBy('sort_order')
		
		crit_ids = [c.id for c in criteria]
		sums = {}
		
		for t in old:
			sum = 0;
			for s in t.scores:
				if s.criterionID in crit_ids and s.criterion.rank != "1":
					try:
						sum += int(s.value)
					except:
						pass
			sums[t.id] = sum
		sum = 0;
		for s in current_assessment.scores:
			if s.criterionID in crit_ids and s.criterion.rank != "1":
				try:
					sum += int(s.value)
				except:
					pass
		sums[current_assessment.id] = sum
		
		util.session('fill', 'missing')
		if len(old) == 0:
			temp = util.session('values', 'zeros')
			if temp == 'previous':
				cherrypy.session['values'] = 'zeros'
		else:
			util.session('values', 'previous')
		
		subtotal = Criterion.selectBy(category=category, level=current_assessment.level, prefix='Z')[0]
		_na = Criterion.selectBy(category=category, level=current_assessment.level, prefix='Y')[0]
		
		oldtotals = {}
		oldna = {}
		percents = {}
		for t in old:
			stscore = Score.selectBy(assessmentID=t.id, criterionID=subtotal.id)
			if stscore.count() > 0:
				stscore = stscore[0]
			else:
				stscore = Score(assessmentID=t.id, criterionID=subtotal.id, value="0", type='subtotal')
			oldtotals[t.id] = stscore.value
			
			nascore = Score.selectBy(assessmentID=t.id, criterionID=_na.id)
			if nascore.count() > 0:
				nascore = nascore[0]
			else:
				nascore = Score(assessmentID=t.id, criterionID=_na.id, value="0", type='na')
			oldna[t.id] = nascore.value
		
			percents[t.id] = util.percent(stscore.value, util.scorePossible(category, current_assessment.level), nascore.value)
			
		
		stscore = Score.selectBy(assessmentID=id, criterionID=subtotal.id)
		nascore = Score.selectBy(assessmentID=id, criterionID=_na.id)
		if stscore.count() > 0:
			stscore = stscore[0]
		else:
			stscore = Score(assessmentID=id, criterionID=subtotal.id, value="0", type='subtotal')
		
		if nascore.count() > 0:
			nascore = nascore[0]
		else:
			nascore = Score(assessmentID=id, criterionID=_na.id, value="0", type='na')
			
		percent = util.percent(stscore.value, util.scorePossible(category, current_assessment.level), nascore.value)
		
		return dict(child=current_child, id=id, a=current_assessment, old=old, oldtotals=oldtotals, \
					stc=subtotal, subtotal=stscore, criteria=criteria, osep=osep, sums=sums, \
					catlist=self.category_list, category=category, nextCategory=self.nextCategory, \
					print_area=print_area, getEditor=self.getEditor, pcheck=self.persistCheck, \
					shaded=util.shaded, scoreclass=util.color, scorePossible=util.scorePossible, \
					nac=_na, na=nascore, oldna=oldna, percents=percents, percent=percent)
Beispiel #15
0
	def index2(self, id=None, category=None, osep='None', print_area='false'):
		if not identity.current.user.basketmode:
			raise redirect(url("index1",id=id,category=category,osep=osep,print_area=print_area))
		
		osep = True

		if print_area == 'true':
			print_area = True
		else:
			print_area = False

		id = util.session('current_assessment', 0, id)
		child = util.session('current_child', 0)

		if id == 0:		# no id given
			raise redirect("/")

		try:
			current_assessment = Assessment.get(id)
		except SQLObjectNotFound:	# Child with given id does not exist
			raise redirect("/")

		current_child = current_assessment.child
		all_assessments = current_child.assessments
		sorted_assessments = Assessment.select(AND(Assessment.q.childID==current_assessment.childID,
												   Assessment.q.id!=id,
												   Assessment.q.level==current_assessment.level), orderBy='-dateEntered')
		old = list(sorted_assessments[:7])


		categories = self.category_list
		data = {}

		for c in categories:
			cdata = {}
			
			subtotal = Criterion.selectBy(category=c, level=current_assessment.level, prefix='Z')[0]
			_na = Criterion.selectBy(category=c, level=current_assessment.level, prefix='Y')[0]

			cdata['subtotal'] = subtotal
			cdata['na'] = _na

			oldtotals = {}
			oldna = {}
			percents = {}
			for t in old:
				stscore = Score.selectBy(assessmentID=t.id, criterionID=subtotal.id)
				if stscore.count() > 0:
					stscore = stscore[0]
				else:
					stscore = Score(assessmentID=t.id, criterionID=subtotal.id, value="0", type='subtotal')
				oldtotals[t.id] = stscore.value

				nascore = Score.selectBy(assessmentID=t.id, criterionID=_na.id)
				if nascore.count() > 0:
					nascore = nascore[0]
				else:
					nascore = Score(assessmentID=t.id, criterionID=_na.id, value="0", type='na')
				oldna[t.id] = nascore.value

				percents[t.id] = util.percent(stscore.value, util.scorePossible(c, current_assessment.level), nascore.value)
			
			cdata['oldtotals'] = oldtotals
			cdata['oldna'] = oldna
			cdata['percents'] = percents

			stscore = Score.selectBy(assessmentID=id, criterionID=subtotal.id)
			nascore = Score.selectBy(assessmentID=id, criterionID=_na.id)
			if stscore.count() > 0:
				stscore = stscore[0]
			else:
				stscore = Score(assessmentID=id, criterionID=subtotal.id, value="0", type='subtotal')

			if nascore.count() > 0:
				nascore = nascore[0]
			else:
				nascore = Score(assessmentID=id, criterionID=_na.id, value="0", type='na')

			percent = util.percent(stscore.value, util.scorePossible(c, current_assessment.level), nascore.value)
			
			cdata['stscore'] = stscore
			cdata['nascore'] = nascore
			cdata['percent'] = percent
			
			data[c] = cdata
			
		baskets = []
		for i in [1,2,3]:
			
			bdata = {}
			
			prefix = "B" + str(i)
			b = Criterion.selectBy(level=current_assessment.level, prefix=prefix)[0]
			
			oldb = {}
			for t in old:
				bscore = Score.selectBy(assessmentID=t.id, criterionID=b.id)
				if bscore.count() > 0:
					bscore = bscore[0]
				else:
					bscore = Score(assessmentID=t.id, criterionID=b.id, value="0", type='basket')
				oldb[t.id] = bscore
			bdata['old'] = oldb
			
			bscore = Score.selectBy(assessmentID=id, criterionID=b.id)
			if bscore.count() > 0:
				bscore = bscore[0]
			else:
				bscore = Score(assessmentID=id, criterionID=b.id, value="0", type='basket')
			bdata['val'] = bscore
			baskets.append(bdata)

		return dict(child=current_child, id=id, a=current_assessment, old=old, categories=categories, \
					print_area=print_area, getEditor=self.getEditor, pcheck=self.persistCheck, \
					shaded=util.shaded, scoreclass=util.color, scorePossible=util.scorePossible, \
					data=data, baskets=baskets)
Beispiel #16
0
	def nextCategory(self):
		category = util.session('current_category', 'Fine Motor')
		for i in range(len(self.category_list)):
			if self.category_list[i] == category:
				return self.category_list[(i+1)%len(self.category_list)]