Example #1
0
def run_program(x):
    lexitize = Lexitize()
    treeitize = Treeitize()
    analyze = Analyze()

    lexOfLexes = lexitize.lexitize(x)
    for lex in lexOfLexes:
        tree = treeitize.treeitize(lex)[0]
        output = analyze.analyze(tree)
        if output is not None:
            return output
Example #2
0
 def run(self):
     for i in range(self.runs):
         S = Simulation(self.timesteps, self.pf_number, self.con_number,
                        self.con_share, self.rest_number)
         S.iterate()
         an = Analyze(S)
         sorted_results = an.sort_pf_by_survival()
         for pf_n in range(self.pf_number):
             self.trans_distrib[pf_n, i] = sorted_results['trans'][pf_n]
             self.rest_distrib[pf_n, i] = sorted_results['rest'][pf_n]
             self.mult_distrib[pf_n, i] = sorted_results['mult'][pf_n]
     self.calc_av(self.trans_distrib, self.trans_av)
     self.calc_av(self.rest_distrib, self.rest_av)
Example #3
0
def analyze(source_path, api):

    # config.txt is used to ignore certain permissions
    print("Looking in root for a config.txt...")
    ignore = {'groups': set(), 'individual': set()}
    try:
        with open("./config.txt") as config:
            for index, line in enumerate(config):

                # ignore commented lines
                if not line.startswith("//"):
                    if line.startswith("#"):
                        # groups -- remove '# ' and add to set
                        sanitized = line[2:].rstrip()
                        ignore['groups'].add(sanitized)
                    elif line != '\n':
                        # specific permissions
                        sanitized = line.rstrip()
                        ignore['individual'].add(sanitized)
        print("Config found. Analysis will ignore the stated permissions.")

    except FileNotFoundError:
        print("Couldn't find a config.txt. Proceeding with analysis")

    # Create reports directory if it doesn't exist
    if not os.path.exists('./reports'):
        os.mkdir('./reports')

    # Parse manifest and validate API
    manifest_tree = get_manifest_tree(source_path)
    validate_minimum_sdk(manifest_tree)

    # Collect permissions
    package_name = get_package_name(manifest_tree)
    permissions = get_requested_permissions(manifest_tree)
    third_party_permissions = get_third_party_permissions(manifest_tree)

    # Scrape the source
    analyzer = Analyze(source_path, package_name, permissions, ignore,
                       str(api))
    source_report = analyzer.search_project_root()

    # Analyze and print results
    report = Report(package_name, permissions, third_party_permissions)
    report.print_analysis(permissions, source_report)
    def testExample2Part2(self):
        print("===============testExample2Part2===============")
        analyzer = Analyze()
        filename = "values2.csv"
        ports = analyzer.portfolio_from_file(filename)
        timestamps = list([i for i in ports.index])
        timestamps.sort()
        vol, daily_ret, sharpe, cum_ret = analyzer.benchmark(["$SPX"], timestamps)

        self.assertAlmostEqual(-0.177204632551, sharpe, 7,"Result Sharpe Ratio: " + str(sharpe) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.0149914504972,vol, 7, "Volatility (stdev of daily returns) " + str(vol) +" is incorrect", delta=None)
        self.assertAlmostEqual(-0.000167347202139, daily_ret, 7, "Average Daily Return " + str(daily_ret) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.937041848381, cum_ret,7, "Result: " + str(cum_ret) +" doesn't match expected Cumulative Return", delta=None)
        
        p2 = analyzer.read_values(filename)
        pt_volatility, pt_daily_return, pt_sharpe_ratio, pt_cumulative_return = analyzer.simulate(p2)
        
        self.assertAlmostEqual(0.788988545538, pt_sharpe_ratio, 6,"Result Sharpe Ratio: " + str(pt_sharpe_ratio) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.00708034656073, pt_volatility, 7, "Volatility (stdev of daily returns) " + str(pt_volatility) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.000351904599618, pt_daily_return, 7, "Average Daily Return " + str(pt_daily_return) +" is incorrect", delta=None)
        self.assertAlmostEqual(1.078753,pt_cumulative_return,7, "Result: " + str(pt_cumulative_return) +" doesn't match expected Cumulative Return", delta=None)
    def testExample1Part2(self):
        print("===============testExample1Part2===============")
        analyzer = Analyze()
        filename = "values1.csv"
        ports = analyzer.portfolio_from_file(filename)
        timestamps = list([i for i in ports.index])
        timestamps.sort()
        vol, daily_ret, sharpe, cum_ret = analyzer.benchmark(["$SPX"], timestamps)

        self.assertAlmostEqual(0.0183391412227, sharpe, 7,"Result Sharpe Ratio: " + str(sharpe) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.0149090969828, vol, 7, "Volatility (stdev of daily returns) " + str(vol) +" is incorrect", delta=None)
        self.assertAlmostEqual(1.72238432443e-05, daily_ret, 7, "Average Daily Return " + str(daily_ret) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.97759401457,cum_ret,7, "Result: " + str(cum_ret) +" doesn't match expected Cumulative Return", delta=None)
        
        p2 = analyzer.read_values(filename)
        pt_volatility, pt_daily_return, pt_sharpe_ratio, pt_cumulative_return = analyzer.simulate(p2)
        
        self.assertAlmostEqual(1.21540462111, pt_sharpe_ratio, 7,"Result Sharpe Ratio: " + str(pt_sharpe_ratio) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.00717514512699, pt_volatility, 7, "Volatility (stdev of daily returns) " + str(pt_volatility) +" is incorrect", delta=None)
        self.assertAlmostEqual(0.000549352749569, pt_daily_return, 7, "Average Daily Return " + str(pt_daily_return) +" is incorrect", delta=None)
        self.assertAlmostEqual(1.13386,pt_cumulative_return,7, "Result: " + str(pt_cumulative_return) +" doesn't match expected Cumulative Return", delta=None)
Example #6
0
 def test_get_outcomes_with_age(self):
     analyze = Analyze()
     result = analyze.readfile()
     lines = analyze.get_lines(result)
     objects = analyze.get_objects(lines)
     result = analyze.get_outcomes_with_age(objects)
     self.assertEqual(28, len(result))
Example #7
0
 def test_get_age_groups(self):
     analyze = Analyze()
     result = analyze.readfile()
     lines = analyze.get_lines(result)
     objects = analyze.get_objects(lines)
     result = analyze.get_age_groups(objects)
     self.assertEqual(10, len(result))
Example #8
0
def main(is_print=False):
    params = {'root_path': root_path}
    processing_ = Processing(params)
    stats = Analyze(processing_.dict_, columns=['title',
                                                'paper_id', 'abstract', 'body_text'])

    if is_print is True:
        print(stats.df_covid.describe(include='all'))

    count = 0
    for x in processing_.dict_['title']:
        if x is "":
            count += 1

    print("\n\n\n\nQuantity of title is empty: {}".format(count))

    return stats
Example #9
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 31 12:05:29 2019

@author: clara
"""
from Simulation import Simulation
from Plot import Plot
from Analyze import Analyze
"""test Simulation"""
S = Simulation(20, 3)
results = S.iterate()

an = Analyze(S)
sorted_results = an.sort_pf_by_survival()

p = Plot()
""" Plot transaction distribution """
p.simple_hist_plot(sorted_results['trans'], 'Transactions per platform')
""" Plot restaurant distribution """
p.simple_hist_plot(sorted_results['rest'], 'Restaurants per platform')

p.cum_hist_plot(sorted_results['trans'], 'Transactions, ')
Example #10
0
fileList = listdir_nohidden(filePath)
process_list = []

for file in fileList:
	#get file path name
	file = join(filePath,file)
	temp = Daily(file)
	process_list.append(temp)


multi = reduce(lambda x,y: x+y, process_list)

print(multi)

"""ANALYZE"""
an = Analyze(multi)


"""increase this number(300) in order to have enough
results to show in registered and unregistered user."""
an.ip_freq(300)

an.classify()

"""There might not enough registered user to show.
output registered user """

fileName = "Registered_User_{}_{}".format(an.day[0],an.day[-1])
with open('Result/{}.txt'.format(fileName), 'w') as f:
	sys.stdout = f
	an.print_registered_user(30)
Example #11
0
def run():
    analyze = Analyze()
    print(analyze.print())
Example #12
0
 def test_getlines(self):
     analyze = Analyze()
     result = analyze.readfile()
     lines = analyze.get_lines(result)
     self.assertEqual(360, len(lines))
Example #13
0
 def test_plot(self):
     analyze = Analyze()
     result = analyze.readfile()
     lines = analyze.get_lines(result)
     objects = analyze.get_objects(lines)
     result = analyze.plot_subs(objects)
Example #14
0
 def test_getobjects(self):
     analyze = Analyze()
     result = analyze.readfile()
     lines = analyze.get_lines(result)
     objects = analyze.get_objects(lines)
     self.assertEqual(20, len(objects))
Example #15
0
def main():
    """Primary driver of MPermission. """

    parser = argparse.ArgumentParser(description='Performs static analysis on\
     decompiled Android M app permissions.')
    parser.add_argument('apk', metavar='APK', nargs=1,
                        help='required APK to decompile or root app to analyze')
    parser.add_argument('--decompile', '-d', action='store_true',
                        help='decompiles the provided APK')
    parser.add_argument('--analyze', '-a', action='store_true',
                        help='analyzes the provided deompiled APK')
    args = parser.parse_args()

    if args.decompile:
        start = time.time()
        decompile(args.apk[0])  # decompile the provided APK
        end = time.time()
        totalTime = end - start
        print ("Time to decompile: %.2f seconds" %totalTime)
    elif args.analyze:

        # config.txt is used to ignore certain permissions
        print("Looking in root for a config.txt...")
        ignore = {
            'groups': set(),
            'individual': set()
        }
        try:
            with open("./config.txt") as config:
                for index, line in enumerate(config):

                    # ignore commented lines
                    if not line.startswith("//"):
                        if line.startswith("#"):
                            # groups -- remove '# ' and add to set
                            sanitized = line[2:].rstrip()
                            ignore['groups'].add(sanitized)
                        elif line != '\n':
                            # specific permissions
                            sanitized = line.rstrip()
                            ignore['individual'].add(sanitized)
            print("Config found. Analysis will ignore the stated permissions.")

        except FileNotFoundError:
            print("Couldn't find a config.txt. Proceeding with analysis")

        # Create reports directory if it doesn't exist
        if not os.path.exists('./reports'):
            os.mkdir('./reports')

        # Parse manifest and validate API
        source_path = args.apk[0]
        manifest_tree = get_manifest_tree(source_path)
        validate_minimum_sdk(manifest_tree)

        # Setup MySQL connection
        try:
            cnx = mysql.connector.connect(host='localhost', user='', database='mpermdb')
            cursor = cnx.cursor()

            # Collect permissions
            package_name = get_package_name(manifest_tree)
            permissions = get_requested_permissions(manifest_tree)
            third_party_permissions = get_third_party_permissions(manifest_tree)

            cursor.execute("SELECT * FROM appinfo WHERE name = \'%s\';" %package_name)

            result = cursor.fetchall()

            with open(source_path + "decompileInfo.txt") as fp:
                for i, line in enumerate(fp):
                    if i == 1:
                        byte = line.rstrip()
                    elif i == 3:
                        apkname = line.rstrip()
                    elif i == 5:
                        daterun = line.rstrip()
                    elif i == 7:
                        decomptime = line.rstrip()
                    elif i > 7:
                        break


            # Placeholders for now
            packagename = package_name
            version = "0"
            
            # Overwrite existing data
            if len(result) > 0:
                print("Updating existing data entry in MySQL table")
                cursor.execute("UPDATE appinfo SET size=\'" + byte + " bytes\', apkname=\'" + apkname + "\', packagename=\'" + packagename + "\', version=\'" + version + "\', daterun=\'" + daterun + "\', decompiletime=\'" + decomptime + " seconds\' WHERE name=\'" + package_name + "\';")
                cnx.commit()
            
            # Add new entry
            else:
                print("Creating new data entry in MySQL table")
                cursor.execute("INSERT INTO appinfo (appid, name, size, apkname, packagename, version, daterun, decompiletime) VALUES (uuid(), \'" + package_name + "\', \'" + byte + " bytes\', \'" + apkname + "\', \'" + packagename + "\', \'" + version + "\', \'" + daterun + "\', \'" + decomptime + " seconds\');")
                cnx.commit()

        except mysql.connector.Error as err:
            if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
                print("Something is wrong with your user name or password")
            elif err.errno == errorcode.ER_BAD_DB_ERROR:
                print("Database does not exist")
            else:
                print(err)
        else:
            cnx.close()

        # Collect permissions
        #package_name = get_package_name(manifest_tree)
        #permissions = get_requested_permissions(manifest_tree)
        #third_party_permissions = get_third_party_permissions(manifest_tree)

        # Scrape the source
        analyzer = Analyze(source_path, package_name, permissions, ignore)
        source_report = analyzer.search_project_root()

        # Analyze and print results
        report = Report(package_name, permissions, third_party_permissions)
        report.print_analysis(permissions, source_report)
    else:
        parser.print_help