Beispiel #1
0
    def get(self):
        organization_id, is_master_org, login_id = get_session_info(request)

        search_tags_query = db.engine.execute("select * from get_alert_search_tags()")
        all_search_tags = []
        for d in search_tags_query:
            all_search_tags.append(dict(d.items()))

        query_text = text("select * from get_alert_history(:lid)")
        alerts = []
        alert_history_id = None
        first_alert_info = None
        alert_values = []

        for alert_info in db.engine.execute(query_text, lid=login_id):
            if alert_info['alert_history_id'] != alert_history_id:
                self.add_alert(first_alert_info, alert_values, alerts, all_search_tags)

                alert_history_id = alert_info['alert_history_id']
                first_alert_info = dict(alert_info.items())
                alert_values = []

            alert_values.append(alert_info['value'])

        self.add_alert(first_alert_info, alert_values, alerts, all_search_tags)

        return jsonify(alerts)
Beispiel #2
0
    def get(self):
        query = PortfolioModel.query

        organization_id, is_master_org, login_id = get_session_info(request)

        if not is_master_org:
            query = query.filter((PortfolioModel.owner_id == organization_id) | (PortfolioModel.owner_id == None))

        result = [model.serialize for model in query]
        return jsonify(result)
Beispiel #3
0
 def get(self):
     _, _, owner_id = get_session_info(request)
     TagHistory.init_flag = 0
     if TagHistory.init_flag == 1:
         self.init_defalut_value()
         TagHistory.init_flag = 0
     args = parser.parse_args()
     if args['delete']:
         TagHistoryModel.query.delete()
         db.session.commit()
         return 'ok', 201
     models = TagHistoryModel.query.filter(
         TagHistoryModel.owner_id == owner_id).order_by(
             TagHistoryModel.id.desc()).all()
     result = [model.serialize for model in models]
     return jsonify(result)
Beispiel #4
0
 def post(self):
     _, _, owner_id = get_session_info(request)
     json = request.get_json()
     if json is None:
         raise BadRequest('JSON POST was expected')
     try:
         tag_history = TagHistoryModel()
         tag_history.owner_id = owner_id
         if not json['name']:
             return jsonify({
                 'success': 0,
                 'message': 'Please enter a name.'
             })
         if not json['tag_combination']:
             return jsonify({
                 'success':
                 0,
                 'message':
                 ' You can’t leave this search bar empty.'
             })
         if json['name'] and json['tag_combination']:
             models = TagHistoryModel.query.filter(TagHistoryModel.owner_id == owner_id,\
                                                     TagHistoryModel.name == json['name']).all()
             if not models:
                 tag_history.name = json['name']
                 tag_history.tag_combination = json['tag_combination']
                 db.session.add(tag_history)
                 db.session.commit()
                 return jsonify({'success': 1})
             else:
                 return jsonify({
                     'success': 0,
                     'message': 'Name is taken. Try again.'
                 })
     except:
         db.session.rollback()
         jsonify({'success': 0})
     finally:
         db.session.close()
Beispiel #5
0
    def post(self):
        """Dismisses all existing alerts available to the currently logged in user

        Returns:
            JSON containing success flag.
        """
        status = 'SUCCESS'

        try:
            _, _, login_id = get_session_info(request)

            Session = sessionmaker(bind=db.engine)
            session = Session()

            query = text("select * from alert_dismiss_all(:lid)")
            session.execute(query, {'lid': login_id})

            session.commit()

        except Exception as e:
            status = 'FAILED'

        return jsonify({'status': status})
Beispiel #6
0
    def post(self, alert_history_id):
        """Given an alert_id, marks it read by the currently logged in user

        Returns:
            JSON containing success flag.
        """
        status = 'SUCCESS'

        try:
            _, _, login_id = get_session_info(request)

            Session = sessionmaker(bind=db.engine)
            session = Session()

            query = text("select * from alert_dismiss(:hid, :lid)")
            session.execute(query, {'hid': int(alert_history_id), 'lid': login_id})

            session.commit()

        except Exception as e:
            status = 'FAILED'

        return jsonify({'status': status})
Beispiel #7
0
    def post(self):
        """Returns tags available to the user based on currently input tags

        This method accepts a JSON list of currently selected tags. All tags passed in should 
        include a tag_type_id property to identify what category of tag it is. Tags such as region 
        and geography should include the level property.
        If no tags are provided (meaning the user has selected no tags yet) only portfolio tags will 
        be returned.

        Returns:
            A dicts containing Portfolio, PortfolioMetrics, ESGMetrics and Properties dicts, each
            with child dicts by type containing allowed tags.
        """
        result = {}

        self._organization_id, self._is_master_org, _ = get_session_info(
            request)

        json = request.get_json()
        if json is None:
            raise BadRequest('JSON POST was expected')

        self._portfolio_list = self._get_tags_by_type(json, TagType.PORTFOLIO)
        self._geography_list = self._get_tags_by_type(json, TagType.REGION)
        self._sector_list = self._get_tags_by_type(json, TagType.SECTOR)
        self._esg_factor_list = self._get_tags_by_type(json,
                                                       TagType.ESG_METRICS)
        self._time_list = self._get_tags_by_type(json, TagType.TIME)
        self._scope_list = self._get_tags_by_type(json,
                                                  TagType.REPORTING_SCOPE)
        self._weight_list = self._get_tags_by_type(json, TagType.WEIGHT_METHOD)
        self._result_list = self._get_tags_by_type(json,
                                                   TagType.PORTFOLIO_METRICS)
        self._control_list = self._get_tags_by_type(json, TagType.CONTROL)

        self._contains_all_portfolios = self._check_list_contains(
            self._portfolio_list, 0)
        self._contains_daily_result_tag = self._check_list_contains(
            self._result_list, PortfolioResultTagType.RETURN_DAILY)
        self._contains_all_securities_tag = self._check_list_contains(
            self._scope_list, ScopeTagType.ALL_SECURITIES)
        self._contains_all_regions_tag = self._check_list_contains(
            self._scope_list, ScopeTagType.ALL_REGIONS)
        self._contains_all_sectors_tag = self._check_list_contains(
            self._scope_list, ScopeTagType.ALL_SECTORS)
        self._contains_all_countries_tag = self._check_list_contains(
            self._scope_list, ScopeTagType.ALL_COUNTRIES)
        self._contains_all_industries_tag = self._check_list_contains(
            self._scope_list, ScopeTagType.ALL_INDUSTRIES)
        self._contains_all_contributors_tag = self._check_list_contains(
            self._scope_list, ScopeTagType.ALL_CONTRIBUTORS)
        self._contains_details_tag = self._check_list_contains(self._scope_list, ScopeTagType.ESG_DETAILS) or \
            self._check_list_contains(self._scope_list, ScopeTagType.UNGC_DETAILS)
        self._contains_analysis_tag = self._check_list_contains(
            self._control_list, ControlTagType.ANALYSIS)
        self._contains_global_map_tag = self._check_list_contains(
            self._control_list, ControlTagType.GLOBAL_MAP)
        self._contains_marginal_contributon_tag = self._check_list_contains(self._control_list, ControlTagType.MARGINAL_BOTTOM_20) or \
            self._check_list_contains(self._control_list, ControlTagType.MARGINAL_TOP_20)
        self._contains_control_tag = self._contains_analysis_tag or self._contains_global_map_tag or self._contains_marginal_contributon_tag

        self._time_scope = self._get_time_scope()

        portfolio_tags = self._get_portfolio_tags()
        result['Portfolio'] = TagsByTags._wrap_tags_dict(
            TagType.PORTFOLIO, 'Portfolio', portfolio_tags)

        if len(json) > 0:
            portfolio_metrics_tags = self._get_results_metrics_tags()
            esg_metrics_tags = self._get_esg_metrics_tags()

            geography_tags, sector_tags = self._get_geography_and_sector_tags()
            time_tags = self._get_time_tags()
            scope_tags = self._get_scope_tags()
            weight_tags = self._get_weight_method_tags()
            control_tags = self._get_control_tags()

            # Move 'ESG details' and 'UNGC details' to ESG metrics tags
            esg_scope_tags = [
                t for t in scope_tags if t['id'] == ScopeTagType.ESG_DETAILS
                or t['id'] == ScopeTagType.UNGC_DETAILS
            ]
            for t in esg_scope_tags:
                esg_metrics_tags.insert(0, t)
                scope_tags.remove(t)

            properties_tags = [
                TagsByTags._wrap_tags_dict(TagType.REGION, 'Region',
                                           geography_tags),
                TagsByTags._wrap_tags_dict(TagType.SECTOR, 'Sector',
                                           sector_tags),
                TagsByTags._wrap_tags_dict(TagType.TIME, 'Time', time_tags),
                TagsByTags._wrap_tags_dict(TagType.REPORTING_SCOPE,
                                           'Reporting Scope', scope_tags),
                TagsByTags._wrap_tags_dict(TagType.WEIGHT_METHOD,
                                           'Weighting Method', weight_tags),
                TagsByTags._wrap_tags_dict(TagType.CONTROL, 'Other',
                                           control_tags)
            ]

            result['PortfolioMetrics'] = TagsByTags._wrap_tags_dict(
                TagType.PORTFOLIO_METRICS, 'Portfolio Metrics',
                portfolio_metrics_tags)
            result['ESGMetrics'] = TagsByTags._wrap_tags_dict(
                TagType.ESG_METRICS, 'ESG Metrics', esg_metrics_tags)
            result['Properties'] = properties_tags

        return jsonify(result)