Exemplo n.º 1
0
def main(PerspectiveAPI):
    parser = argparse.ArgumentParser(
        description='Add toxicity score to email dataframe',
        prog='enron_emails_toxity_score.py',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-f",
                        "--file",
                        dest='file',
                        required=True,
                        type=str,
                        help='Input email pickle file')
    parser.add_argument("-a",
                        "--api",
                        dest='api',
                        required=True,
                        type=str,
                        help='API file')
    parser.add_argument("-o",
                        "--out",
                        dest='out',
                        type=str,
                        help='output file',
                        default='scored.pkl')
    parser.add_argument('-t', action='store_true')

    args = parser.parse_args()

    with (open(args.file, "rb")) as openfile:
        df = pickle.load(openfile)

    df = df[50000:]

    with open(args.api) as f:
        google_api_key = PerspectiveAPI
    client = perspective.Perspective(google_api_key)

    def calculate_score(text):
        try:
            time.sleep(1)  # limit API calls to 1 per second
            score = client.score(text, tests=["TOXICITY"])
        except:
            return -1.0
        else:
            return score["TOXICITY"].score

    if (args.t):
        df = df.head(10)

    df['toxicity_score'] = df.content.apply(calculate_score)
    df.to_pickle(args.out)
Exemplo n.º 2
0
    def render(self, display, getValueFn, setPosFn):
        # camera pos indication
        if setPosFn is not None:
            theta = math.radians(90 - getValueFn("camera_altitude"))
            phi = math.radians(90 - getValueFn("camera_azimuth"))
            r = getValueFn("camera_distance")
            y = r * math.cos(theta)
            x = r * math.cos(phi) * math.sin(theta)
            z = r * math.sin(phi) * math.sin(theta)
            pos = "x:%d  y:%d  z:%d" % (x, y, z)
            setPosFn(pos)

        # create perspective
        persp = perspective.Perspective(getValueFn("camera_azimuth"),
                                        getValueFn("camera_altitude"),
                                        getValueFn("camera_distance"),
                                        getValueFn("camera_fov"))

        # Cone
        self.cone_height = getValueFn("cone_height")
        self.cone_radius = getValueFn("cone_radius")
        self.plane_tilt = math.radians(getValueFn("plane_tilt"))

        # camera
        self.camera_altitude = getValueFn("camera_altitude")
        self.setCameraPos(persp.getCamera())

        # compute 3D -> 2D
        shapes = self.makeShapes()
        for each in shapes:
            if each is None:
                continue
            show = True
            try:
                each.render(display, persp, show=show)
            except ValueError, e:
                traceback.print_exc()
                print e
                pass  # some point cannot be rendered
            except OverflowError, e:
                traceback.print_exc()
                print e
                pass  # some point cannot be rendered
Exemplo n.º 3
0
 def setUpClass(cls):
     cls._testfile = nfile.NidhoggFile('corpus/alice_in_wonderland.txt.bz2')
     cls._scanner = perspective.Perspective(cls._testfile)
     cls._template = nwriter.NidhoggLoader('perspectivetest.xml')
Exemplo n.º 4
0
runSecondVideo = False
runThirdVideo = False

# load parameters
params = params.Params() # could be extended to load from external file some day ...

# camera calibration
cal = calibrate.Calibrate("../camera_cal/*", 9,6)
# test whether calibration worked
cal.distortionAndTransformPerspective_testFiles("../test_camera_cal")


# perspective transform
points = params.points
# calc perspective transform
per = perspective.Perspective("../test_images/straight_lines1.jpg", points)

lanes = lanes.Lanes(per, cal, params) # reset lanes

# apply pipeline to test images
if runTestImages == True:
    test_images = glob.glob("../test_images/*")
    for f in test_images:

        lanes.reset() # reset lanes

        img = cv2.imread(f)

        out = lanes.findLanes(img)

        cv2.imwrite(os.path.join("../output_images", os.path.basename(f)), out)
Exemplo n.º 5
0
Arquivo: home.py Projeto: atsta/MuPIA
def main():
#temporarily tertiary prices
    energy_price_with_taxes = {
        "electricity": 166.4,
        "diesel_oil": 79.5,
        "motor_gasoline": 134.7, 
        "natural_gas": 62.0, 
        "biomass": 64.6
    }

    energy_price_without_taxes = {
        "electricity": 116,
        "diesel_oil": 41.8,
        "motor_gasoline": 45, 
        "natural_gas": 51, 
        "biomass": 52.1
    }

    energy_conservation = {
            "electricity": 0,
            "diesel_oil": 42.0,
            "motor_gasoline": 0, 
            "natural_gas": 65.0, 
            "biomass": 0
    }

    energy_price_growth_rate = {
        "electricity": 0.015,
        "diesel_oil": 0.025,
        "motor_gasoline": 0.025, 
        "natural_gas": 0.017, 
        "biomass": 0.02
    }

    m = energy_measure.Measure("test_social", 3)
    print(m.specs)
    print(m.energy_conservation)

    selected_benefits = ["energy_savings", "maintenance", "residual_value", "tax_depreciation"]
    selected_costs = ["equipment"]

    #SCBA
    # social = social_investment_analysis.Social(m.specs, m.energy_conservation, m.energy_price_without_taxes, m.energy_price_growth_rate, selected_costs, selected_benefits, 25, 0.03)
    
    # print(social.benefits)
    # print(social.costs)
    # print(social.pure_cash_flow)
    # print(social.cost_pv)
    # print(social.benefit_pv)
    # print(social.npv)
    # print(social.b_to_c)
    # print(social.irr)
    # print(social.pbp)



    #FCBA

    # financial = financial_investment_analysis.Financial(m.specs, m.energy_conservation, m.energy_price_with_taxes, m.energy_price_growth_rate, selected_costs, selected_benefits, 25, 0.05)
    
    # print(financial.benefits)
    # print(financial.costs)
    # print(financial.pure_cash_flow)
    # print(financial.cost_pv)
    # print(financial.benefit_pv)
    # print(financial.npv)
    # print(financial.b_to_c)
    # print(financial.irr)
    # print(financial.pbp)



    #PERSPECTIVE

    sub = financial_mechanism.Subsidy(m.specs, 0.4)
    tax = financial_mechanism.Tax_depreciation(0.25, 0.1, 10)

    if sub.subsidy_rate > 0:
        logistic_cost = m.specs['cost']*1.24*(1-sub.subsidy_rate)
    else:
        logistic_cost = m.specs['cost']*1.24
      
    loan = financial_mechanism.Loan(logistic_cost, 0.5, 0.08, 0.024, 3, 0)
    
    esco_loan = financial_mechanism.Loan(m.specs['cost'], 0.5, 0.08, 0.024, 10, 0)

    test_esco = financial_mechanism.Esco(m.specs, [], 0, " ", 0, " ", 0, 0, 0, 0, esco_loan)

    test_per = perspective.Perspective(m.specs, energy_conservation, energy_price_with_taxes, energy_price_growth_rate, selected_costs, selected_benefits, 25, 0.05, sub, loan, test_esco, tax)

    esco_actor = financial_mechanism.Esco(m.specs, test_per.savings_per_year_taxable, 0, "npv", 8328, "benefit_share", 0.06, 0.8, 0.7, 8, esco_loan)
    
        
    p =  perspective.Perspective(m.specs, m.energy_conservation, m.energy_price_with_taxes, m.energy_price_growth_rate, selected_costs, selected_benefits, 25, 0.05, sub, loan, esco_actor, tax)



    print(p.benefits)
    print(p.costs)
    print(p.pure_cash_flow)
    print(p.cost_pv)
    print(p.benefit_pv)
    print(p.npv)
    print(p.b_to_c)
    print(p.irr)
    print(p.pbp)
    print(esco_actor.benefit_share_rate)


    #root= tk.Tk()

    #canvas1 = tk.Canvas(root, width = 300, height = 300, bg = 'lightsteelblue2', relief = 'raised')
    #canvas1.pack()

    saveAsButton_CSV = tk.Button(text='Export CSV', command=exportCSV(p.benefits), bg='green', fg='white', font=('helvetica', 12, 'bold'))