Ejemplo n.º 1
0
def create_deals():
    deals = load_json('sharks.json')

    for oneDeal in deals['deals']:
        name = oneDeal["name"]
        id = oneDeal["id"]
        url = oneDeal["url"]
        episode = oneDeal["episode"]
        founders = oneDeal["founders"]
        location = oneDeal["location"]
        description = oneDeal["description"]
        investment = oneDeal["investment"]
        equity = oneDeal["equity"]
        picture = oneDeal["picture"]
        sharks = oneDeal["sharks"]
        sharksURL = oneDeal["sharksURL"]

        newDeal = Investment(name=name,
                             id=id,
                             url=url,
                             episode=episode,
                             founders=founders,
                             location=location,
                             description=description,
                             investment=investment,
                             equity=equity,
                             picture=picture,
                             sharks=sharks,
                             sharksURL=sharksURL)

        db.session.add(newDeal)
        db.session.commit()
Ejemplo n.º 2
0
    def investi(self, sess, comment, investor, amount, suffix):
        """
        This function invests
        """
        if config.CLOSED:
            return comment.reply_wrap(message.CLOSED_ORG)

        multiplier = CommentWorker.multipliers.get(suffix, 1)

        # Allows input such as '!invest 100%' and '!invest 50%'
        if multiplier == "%":
            amount = int(investor.balance * (int(amount) / 100))
        else:
            try:
                amount = int(amount.replace(",", ""))
                amount = amount * multiplier
            except ValueError:
                return

        # Sets the minimum investment to 1% of an investor's balance or 100 Mc
        minim = int(investor.balance / 100)
        if amount < minim or amount < 100:
            return comment.reply_wrap(message.modify_min_invest(minim))

        author = comment.author.name
        new_balance = investor.balance - amount

        if new_balance < 0:
            return comment.reply_wrap(message.modify_insuff(investor.balance))

        upvotes_now = int(comment.submission.ups)
        # apply 15 minute grace period
        if comment.created_utc - comment.submission.created_utc < 60 * 15:
            upvotes_now = min(upvotes_now,
                              int(math.pow(3, upvotes_now / 5) - 1))
        # 0 upvotes is too strong, so what we do is make around 1 minumum
        if upvotes_now < 1:
            upvotes_now = 1
        deltatime = min(
            int((comment.created_utc - comment.submission.created_utc) / 60),
            60)

        # Sending a confirmation
        response = comment.reply_wrap(
            message.modify_invest(amount, upvotes_now, new_balance))

        sess.add(
            Investment(
                post=comment.submission.id,
                upvotes=upvotes_now,
                deltatime=deltatime,
                comment=comment.id,
                name=author,
                amount=amount,
                response=response.id,
                done=False,
            ))

        investor.balance = new_balance
Ejemplo n.º 3
0
    def update_fundingconnections(connections, ftype, direction):
        # Delete and connections that have been removed.
        new_connections = [connection['id'] for connection in connections if connection['id']]
        # TODO: See if you can make this generic to handle any set of connections for simplicity.
        # TODO: Maybe list comprehensions in stead depending on how cascade='delete-orphan' works.
        if ftype is 'investment':
            if direction is 'given':
                for connection in entity.investments_made:
                    if connection.id not in new_connections:
                        db.delete(connection)
            elif direction is 'received':
                for connection in entity.investments_received:
                    if connection.id not in new_connections:
                        db.delete(connection)
        elif ftype is 'grant':
            if direction is 'given':
                for connection in entity.grants_given:
                    if connection.id not in new_connections:
                        db.delete(connection)
            elif direction is 'received':
                for connection in entity.grants_received:
                    if connection.id not in new_connections:
                        db.delete(connection)
        db.commit()

        for connection in connections:
            if connection['id']:
                # Connection exists, update amount and year.
                oldconnection = Fundingconnection.query.get(connection['id'])
                if oldconnection.amount != connection['amount']:
                    oldconnection.amount = connection['amount']
                    app.logger.debug('UPDATING ' + ftype + ' AMOUNT: ' + str(oldconnection.amount))
                if oldconnection.year != connection['year']:
                    oldconnection.year = connection['year']
                    app.logger.debug('UPDATING ' + ftype + ' YEAR: ' + str(oldconnection.year))
            elif 'entity_id' in connection:
                # Connection doesn't exist, create it connect entities.
                otherentity = Entity.query.get(connection['entity_id'])
                if ftype is 'investment':
                    newconnection = Investment(connection['amount'], connection['year'])
                    if direction is 'given':
                        entity.investments_made.append(newconnection)
                        otherentity.investments_received.append(newconnection)
                    elif direction is 'received':
                        entity.investments_received.append(newconnection)
                        otherentity.investments_made.append(newconnection)
                elif ftype is 'grant':
                    newconnection = Grant(connection['amount'], connection['year'])
                    if direction is 'given':
                        entity.grants_given.append(newconnection)
                        otherentity.grants_received.append(newconnection)
                    elif direction is 'received':
                        entity.grants_received.append(newconnection)
                        otherentity.grants_given.append(newconnection)
        db.commit()
Ejemplo n.º 4
0
 def test_source_insert_4(self):
     i = Investment(name='JUUL',
                    id=10,
                    episode=1,
                    founders=['Jamaes Monsees', 'Adam Bowen'])
     db.session.add(i)
     db.session.commit()
     r = db.session.query(Investment).filter_by(id=10).one()
     self.assertEqual(str(r.id), str(10))
     db.session.query(Investment).filter_by(id=10).delete()
     db.session.commit()
Ejemplo n.º 5
0
 def test_source_insert_5(self):
     i = Investment(name='NASA',
                    id=2,
                    episode=15,
                    founders=['Dwight D. Eisenhower'])
     db.session.add(i)
     db.session.commit()
     r = db.session.query(Investment).filter_by(id=2).one()
     self.assertEqual(str(r.id), str(2))
     db.session.query(Investment).filter_by(id=2).delete()
     db.session.commit()
Ejemplo n.º 6
0
 def test_source_insert_4(self):
     i = Investment(name='Coca Cola',
                    id=5,
                    episode=10,
                    founders=['Asa Griggs Candler'])
     db.session.add(i)
     db.session.commit()
     r = db.session.query(Investment).filter_by(id=5).one()
     self.assertEqual(str(r.id), str(5))
     db.session.query(Investment).filter_by(id=5).delete()
     db.session.commit()
Ejemplo n.º 7
0
def aggregate(input_file, date):
    df = pd.read_csv('./input/' + input_file, header=None)
    df.columns = ['date', 'shares', 'cash_raised', 'investor']
    df = df[df['date'] < date]

    total_share = df['shares'].sum()
    total_cash_raised = df['cash_raised'].sum()

    e = pd.Series(np.random.randn(len(df['date'])))
    df['ownership'] = df['shares'].map(lambda share: round(share / total_share * 100, 2))
    df_sum = df.groupby('investor').sum()

    def reduce(row, investment):
        ownership = Ownership(row.name, row['shares'], row['cash_raised'], row['ownership'])
        investment.ownership.append(ownership)
        return investment

    investment = Investment(date, total_share, total_cash_raised)
    df_sum.apply(reduce, axis=1, args=[investment])

    return json.dumps(investment.toJSON(), indent=4, separators=(',',':'))
Ejemplo n.º 8
0
 def create_investment(self, amount, start_upvotes, end_upvotes, iid='0'):
     investor = Investor(name='investor' + iid)
     submission = Submission('sid' + iid)
     comment = Comment('cid' + iid, investor.name, 'dummy', submission)
     self.reddit.add_submission(submission)
     investment = Investment(
         post=comment.submission.id,
         upvotes=start_upvotes,
         comment=comment.id,
         name=comment.author.name,
         amount=amount,
         response="0",
         done=False,
     )
     investment.time = int(time.time()) - config.INVESTMENT_DURATION - 1
     submission.ups = end_upvotes
     sess = self.Session()
     sess.add(investor)
     sess.add(investment)
     sess.commit()
     return investor, investment
Ejemplo n.º 9
0
    def invest(self, sess, comment, investor, amount, suffix):
        """
        This function invests
        """
        if config.PREVENT_INSIDERS:
            if comment.submission.author.name == comment.author.name:
                return comment.reply_wrap(message.INSIDE_TRADING_ORG)
        multiplier = CommentWorker.multipliers.get(suffix, 1)

        # Allows input such as '!invest 100%' and '!invest 50%'
        if multiplier == '%':
            amount = int(investor.balance * (int(amount)/100))
        else:
            try:
                amount = int(amount.replace(',', ''))
                amount = amount * multiplier
            except ValueError:
                return

        # Sets the minimum investment to 1% of an investor's balance or 100 Mc
        minim = int(investor.balance / 100)
        if amount < minim or amount < 100:
            return comment.reply_wrap(message.modify_min_invest(minim))

        author = comment.author.name
        new_balance = investor.balance - amount

        if new_balance < 0:
            return comment.reply_wrap(message.modify_insuff(investor.balance))

        # Sending a confirmation
        response = comment.reply_wrap(message.modify_invest(
            amount,
            comment.submission.ups,
            new_balance
        ))

        # 0 upvotes is too OP, so what we do is make around 5 minumum
        upvotes_now = int(comment.submission.ups)
        if upvotes_now < 5:
            upvotes_now = 5

        sess.add(Investment(
            post=comment.submission,
            upvotes=upvotes_now,
            comment=comment,
            name=author,
            amount=amount,
            response=response,
            done=False,
        ))

        investor.balance = new_balance
Ejemplo n.º 10
0
def contact_civ(request):
    investor = Investment.objects.filter()
    if request.method == 'POST':
        invest = Investment()
        form = InvestForm(request.POST, instance=invest)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/mobile/invest_confirm/' +
                                        str(invest.id))
    else:
        form = InvestForm()
    t = loader.get_template('civ/register.html')
    c = Context({'form': form.as_p()})
    return HttpResponse(t.render(c))
Ejemplo n.º 11
0
    def invest(self, sess, comment, investor, amount):
        # Post related vars
        if not investor:
            return

        if comment.submission.author.name == comment.author.name:
            comment.reply(message.inside_trading_org)
            return

        try:
            amount = int(amount)
        except ValueError:
            return

        if amount < 100:
            comment.reply_wrap(message.min_invest_org)
            return

        author = comment.author.name
        new_balance = investor.balance - amount

        if new_balance < 0:
            comment.reply_wrap(message.insuff_org)
            return

        # Sending a confirmation
        response = comment.reply_wrap(message.modify_invest(
            amount,
            comment.submission.ups,
            new_balance
        ))

        sess.add(Investment(
            post=comment.submission,
            upvotes=comment.submission.ups,
            comment=comment,
            name=author,
            amount=amount,
            response=response,
            done=False,
        ))

        sess.query(Investor).\
            filter(Investor.name == author).\
            update({
                Investor.balance: new_balance,
            }, synchronize_session=False)
Ejemplo n.º 12
0
    def invest(self, sess, comment, investor, amount):
        if not isinstance(comment, praw.models.Comment):
            return

        if config.prevent_insiders:
            if comment.submission.author.name == comment.author.name:
                comment.reply_wrap(message.inside_trading_org)
                return

        try:
            amount = int(amount)
        except ValueError:
            return

        if amount < 100:
            comment.reply_wrap(message.min_invest_org)
            return

        author = comment.author.name
        new_balance = investor.balance - amount

        if new_balance < 0:
            comment.reply_wrap(message.insuff_org)
            return

        # Sending a confirmation
        response = comment.reply_wrap(message.modify_invest(
            amount,
            comment.submission.ups,
            new_balance
        ))

        sess.add(Investment(
            post=comment.submission,
            upvotes=comment.submission.ups,
            comment=comment,
            name=author,
            amount=amount,
            response=response,
            done=False,
        ))

        investor.balance = new_balance
    def invest(self, sess, comment, investor, amount, suffix):
        """
        This function invests
        """
        if config.PREVENT_INSIDERS:
            if comment.submission.author.name == comment.author.name:
                comment.reply_wrap(message.INSIDE_TRADING_ORG)
                return

        try:
            amount = float(amount.replace(',', ''))
            amount = int(amount * CommentWorker.multipliers.get(suffix, 1))
        except ValueError:
            return

        if amount < 100:
            comment.reply_wrap(message.MIN_INVEST_ORG)
            return

        author = comment.author.name
        new_balance = investor.balance - amount

        if new_balance < 0:
            comment.reply_wrap(message.modify_insuff(investor.balance))
            return

        # Sending a confirmation
        response = comment.reply_wrap(
            message.modify_invest(amount, comment.submission.ups, new_balance))

        sess.add(
            Investment(
                post=comment.submission,
                upvotes=comment.submission.ups,
                comment=comment,
                name=author,
                amount=amount,
                response=response,
                done=False,
            ))

        investor.balance = new_balance
Ejemplo n.º 14
0
 def create_investment(self, amount, iid="0"):
     investor = Investor(name="investor" + iid)
     submission = Submission("sid" + iid)
     comment = Comment("cid" + iid, investor.name, "dummy", submission)
     self.reddit.add_submission(submission)
     investment = Investment(
         post=comment.submission.id,
         upvotes=1,
         comment=comment.id,
         name=comment.author.name,
         amount=amount,
         response="0",
         done=False,
     )
     buyable = Buyable(post=submission.id,
                       name=submission.author.name,
                       response="brid" + iid)
     buyable.time = int(time.time()) - config.INVESTMENT_DURATION - 1
     sess = self.session
     sess.add(buyable)
     sess.add(investor)
     sess.add(investment)
     sess.commit()
     return investor, buyable, submission
Ejemplo n.º 15
0
 def add_investment(self, tranche, investor, sum_invest, date_invest):
     self.investments.append(
         Investment(tranche, investor, sum_invest, date_invest))