Esempio n. 1
0
    def testInit(self):
       
        print 'testInit ...'
        
        # Test with an invalid config file.
        with self.assertRaises(TypeError):
            trials = Trials(None, True)
        
        with self.assertRaises(IOError):
            trials = Trials('Nonexistent file', True)
        
        # Create a config file.
        mmxConfig = MmxConfig()
        presFile  = 'tests/WLBG-geog.csv'
        startDate = '1-1-2016'
        endDate   = '1-1-2017'
        outDir    = '../'
        numProcs  = 500
        numTrials = 200
        species   = 'WLBG'
        
        mmxConfig.initializeFromValues(presFile, startDate, endDate, species,
                                       outDir, numProcs, numTrials)
                                       
        mmxConfig.write()

        # Initialize GetMerra 
        mmxConfig.setStateComplete()
        trials = Trials(mmxConfig.getConfigFile(), True)
Esempio n. 2
0
def main():
    conf = Config()
    db = Database(conf.address, conf.username, conf.password,
                  conf.database_name)

    valid_studies_counter = 0

    for i in range(0, count):
        try:
            scraped_url = "http://drks-neu.uniklinik-freiburg.de/drks_web/navigate.do?navigationId=trial.HTML&TRIAL_ID=DRKS" + str(
                i).zfill(8)
            request = requests.get(scraped_url, stream=True)
            request.encoding = 'utf-8'

            my_scraper = BeautifulSoup(request.text.encode('utf8'), "lxml")

            if not (my_scraper.find('ul', class_="error")
                    or my_scraper.find('ul', class_="errors")):
                # if true webpage contains valid data of study
                Trials(my_scraper, db)
                valid_studies_counter += 1

            sys.stdout.write("\r Processing " + str(i) + "/" + str(count) +
                             " => " + str(i * 100 / count) + " percent\t\t" +
                             str(valid_studies_counter) + " studies found")
            sys.stdout.flush()
        except AttributeError:
            print("\n[-] attribute error at " + str(i))
        except Exception:
            print("\n[-] unknown error at " + str(i))

    db.close_connection()
Esempio n. 3
0
    def testGenerateFileIndexes(self):
       
        print 'testGenerateFileIndexes ...'
        
        mmxConfig = MmxConfig()
        presFile  = 'tests/WLBG-geog.csv'
        startDate = '1-1-2016'
        endDate   = '1-1-2017'
        outDir    = '../'
        numProcs  = 500
        numTrials = 200
        species   = 'WLBG'
        
        mmxConfig.initializeFromValues(presFile, startDate, endDate, species,
                                       outDir, numProcs, numTrials)

        mmxConfig.write()

        trials = Trials(mmxConfig.getConfigFile(), True)
        trials.generateFileIndexes(50)
Esempio n. 4
0
    def testGetPhase(self):
       
        print 'testGetPhase ...'
        
        mmxConfig = MmxConfig()
        presFile  = 'tests/WLBG-geog.csv'
        startDate = '1-1-2016'
        endDate   = '1-1-2017'
        outDir    = '../'
        numProcs  = 500
        numTrials = 200
        species   = 'WLBG'
        
        mmxConfig.initializeFromValues(presFile, startDate, endDate, species,
                                       outDir, numProcs, numTrials)
                                       
        mmxConfig.write()

        # Initialize GetMerra 
        mmxConfig.setStateComplete()
        trials = Trials(mmxConfig.getConfigFile(), True)
        self.assertEqual(trials.config.phase, 'TRIALS')
Esempio n. 5
0
	def test(self, data, control, variations):
		update = {}
		buckets = [control] + variations
		for bucket in buckets:
			total = data[bucket][0]['count']
			successes = data[bucket][1]['count']
			update[bucket] = (successes, total - successes)

		test = Trials(buckets)
		test.update(update)

		dominances = test.evaluate('dominance', control=control)
		lifts = test.evaluate('expected lift', control=control)
		intervals = test.evaluate('lift CI', control=control, level=95)

		for variation in variations:
			print('Variation {name}:'.format(name=variation))
			s, t = update[variation]
			print('* Successes: {0}, Total: {1}, Percent: {2:2.3f}%'.format(s, t, 100*float(s)/t))
			print('* E[lift] = {value:.2%}'.format(value=lifts[variation]))
			print('* P({lower:.2%} < lift < {upper:.2%}) = 95%'.format(lower=intervals[variation][0], upper=intervals[variation][2]))
			print('* P({name} > {control}) = {value:.2%}'.format(name=variation, control=control, value=dominances[variation]))
			print
Esempio n. 6
0
"""Sociological poll example."""

import sys
sys.path.append('..')

from trials import Trials

if __name__ == '__main__':
    test = Trials(['Poroshenko', 'Tymoshenko'])

    test.update({'Poroshenko': (48, 52), 'Tymoshenko': (12, 88)})

    estimates = test.evaluate('posterior CI')
    dominance = test.evaluate('dominance', control='Tymoshenko')

    print('Poroshenko estimated vote share: {lower:.2%} - {upper:.2%} '
          '(95% credibility)'.format(lower=estimates['Poroshenko'][0],
                                     upper=estimates['Poroshenko'][2]))

    print('Tymoshenko estimated vote share: {lower:.2%} - {upper:.2%} '
          '(95% credibility)'.format(lower=estimates['Tymoshenko'][0],
                                     upper=estimates['Tymoshenko'][2]))

    print('Chance that Poroshenko beats Tymoshenko based on the poll data: '
          '{chance:.2%}'.format(chance=dominance['Poroshenko']))
Esempio n. 7
0
import sys
sys.path.append('..')

from trials import Trials


if __name__ == '__main__':
    test = Trials(['A', 'B', 'C'])

    test.update({
        'A': (50, 10),
        'B': (75, 15),
        'C': (20, 15)
    })

    lift = test.evaluate('lift', control='A')
    domination = test.evaluate('domination', control='A')

    for variation in ['B', 'C']:
        print('Variation {name}:'.format(name=variation))
        print('* lift = {value:.2%}'.format(value=lift[variation]))
        print('* P({name} > {control}) = {value:.2%}' \
            .format(name=variation, control='A', value=domination[variation]))
Esempio n. 8
0
"""Sociological poll example."""

import sys
sys.path.append('..')

from trials import Trials


if __name__ == '__main__':
    test = Trials(['Poroshenko', 'Tymoshenko'])

    test.update({
        'Poroshenko': (48, 52),
        'Tymoshenko': (12, 88)
    })

    estimates = test.evaluate('posterior CI')
    dominance = test.evaluate('dominance', control='Tymoshenko')

    print('Poroshenko estimated vote share: {lower:.2%} - {upper:.2%} '
          '(95% credibility)'
          .format(lower=estimates['Poroshenko'][0],
                  upper=estimates['Poroshenko'][2]))

    print('Tymoshenko estimated vote share: {lower:.2%} - {upper:.2%} '
          '(95% credibility)'
          .format(lower=estimates['Tymoshenko'][0],
                  upper=estimates['Tymoshenko'][2]))

    print('Chance that Poroshenko beats Tymoshenko based on the poll data: '
          '{chance:.2%}'.format(chance=dominance['Poroshenko']))
Esempio n. 9
0
"""Simple A/B test example."""

import sys
sys.path.append('..')

from trials import Trials


if __name__ == '__main__':
    test = Trials(['A', 'B', 'C'])

    test.update({
        'A': (50, 10),
        'B': (75, 15),
        'C': (20, 15)
    })

    dominance = test.evaluate('dominance', control='A')
    lift = test.evaluate('expected lift', control='A')
    interval = test.evaluate('lift CI', control='A', level=95)

    for variation in ['B', 'C']:
        print('Variation {name}:'.format(name=variation))
        print('* E[lift] = {value:.2%}'.format(value=lift[variation]))
        print('* P({lower:.2%} < lift < {upper:.2%}) = 95%'
              .format(lower=interval[variation][0],
                      upper=interval[variation][2]))
        print('* P({name} > {control}) = {value:.2%}'
              .format(name=variation, control='A',
                      value=dominance[variation]))