Exemplo n.º 1
0
def datamodel_statistic_report_view(request):
    #response = HttpResponse(content_type='text/plain')
    response = HttpResponse()
    content = '<table border="1px solid black">'
    codename_list = FundCodeModel.get_codename_list()
    for t_code, t_name in codename_list[:]:
        ancestor = FundClearInfoModel.get_by_key_name(
            FundClearInfoModel.compose_key_name(t_code))
        if ancestor is None:
            t_count = 0
            t_years = ''
        else:
            t_funddata_query = FundClearDataModel.all().ancestor(
                ancestor).order('year')
            t_count = 0
            t_years = ''
            for t_funddata in t_funddata_query:
                t_count += 1
                if t_funddata.year is None:
                    t_years += '?,'
                else:
                    t_years += t_funddata.year + ', '
        t_report = '<tr><td width="10%" align="right">{}</td><td width="5%" align="right">{}</td><td width="50%">{}</td><td>{}</td></tr>\n'.format(
            t_code,
            t_count,
            t_name,
            t_years,
        )
        content += t_report

    content += '</table>'
    response.content = content
    return response
Exemplo n.º 2
0
def fc2_review_cupdate_taskhandler(request):
    response = HttpResponse('fc2_review_cupdate_taskhandler')

    UPDATE_SIZE = 5
    try:
        fundcode_list = FundCodeModel.get_codename_list()

        #logging.debug('fc2_review_cupdate_taskhandler: debug mode!!!')
        #fundcode_list = fundcode_list[:]

        fund_index = int(request.REQUEST['PARAM1'])
        logging.info(
            'fc2_review_cupdate_taskhandler: start with index {ind}'.format(
                ind=fund_index))

        for i in range(UPDATE_SIZE):
            next_index = fund_index + i
            if next_index < len(fundcode_list):
                fund_code = fundcode_list[next_index][0]
                logging.info(
                    'fc2_review_cupdate_taskhandler: index {ind} get fund code {fund_code}'
                    .format(ind=next_index, fund_code=fund_code))
                taskqueue.add(method='GET',
                              url=get_fc_update_taskhandler_url(),
                              countdown=2,
                              params={
                                  'PARAM1': fund_code,
                              })
            else:
                logging.info(
                    'fc2_review_cupdate_taskhandler: end of chain update task.'
                )
                break

        if (fund_index + UPDATE_SIZE) < len(fundcode_list):
            logging.debug(
                'fc2_review_cupdate_taskhandler: add next chain update task with index {index}'
                .format(index=fund_index + UPDATE_SIZE))
            taskqueue.add(method='GET',
                          url=get_fc_cupdate_taskhandler_url(),
                          countdown=5,
                          params={
                              'PARAM1': str(fund_index + UPDATE_SIZE),
                          })
        response.status_code = httplib.OK
        return response
    except Exception, e:
        response.status_code = httplib.INTERNAL_SERVER_ERROR
        logging.error('fc2_review_update_taskhandler exception: {msg}'.format(
            msg=str(e)))
Exemplo n.º 3
0
def fund_analysis_view(request, p_key=None):
    response = HttpResponse()
    codename_all = FundCodeModel.get_codename_list()
    t_count = 1
    t_table = '<table border="1px solid black">{}{}</table>\n'
    t_thead = ''
    t_tbody = ''
    t_keys = []
    for (t_code, t_name) in codename_all[:]:
        t_reviews = fundtask.get_analysis(t_code)
        if t_thead == '':
            t_thead = '<tr><td>No</td><td>ID</td><td>Name</td>\n'
            if p_key is None:
                for t_key in sorted(t_reviews.keys()):
                    t_thead += '<td>{}</td>'.format(t_key)
                    t_keys.append(t_key)
            else:
                if p_key in t_reviews.keys():
                    t_thead += '<td>{}</td>'.format(p_key)
                    t_keys.append(p_key)
                else:
                    response.content = 'key {} not exist!!!'.format(p_key)
                    return response
            t_thead += '</tr>\n'

        if p_key is None:
            t_row = '<tr><td>{}</td><td>{}</td><td>{}</td>'.format(
                t_count, t_code, t_name)
            for t_key in t_keys:
                t_row += '<td>{}</td>'.format(t_reviews[t_key])
            t_row += '</tr>\n'
            t_tbody += t_row
        else:
            if t_reviews[p_key]:
                t_row = '<tr><td>{}</td><td>{}</td><td>{}</td>'.format(
                    t_count, t_code, t_name)
                for t_key in t_keys:
                    t_row += '<td>{}</td>'.format(t_reviews[t_key])
                t_row += '</tr>\n'
                t_tbody += t_row
        t_count += 1

    response.content = t_table.format(t_thead, t_tbody)
    return response
Exemplo n.º 4
0
def list_all_fund_view(request):
    t_fundcode_list = FundCodeModel.get_codename_list()

    content_head_list = [
        'Code', 'Name', 'BB View', 'NAV View', 'Update', 'Year Detail',
        'SRC View'
    ]
    content_rows = []
    this_year = date.today().year
    t_begin_date = date(this_year - 2, 1, 1).strftime("%Y/%m/%d")
    t_end_date = date.today().strftime("%Y/%m/%d")

    for t_entry in t_fundcode_list:
        #t_entry[2] = '<a href="/mf/bb/'+t_entry[1]+'/">' + t_entry[2] + "</a>"
        #t_entry[2] = '<a href="/fc/flot/'+t_entry[1]+'/">' + t_entry[2] + "</a>"
        src_url = fc2.URL_TEMPLATE.format(fund_id=t_entry[0],
                                          begin_date=t_begin_date,
                                          end_date=t_end_date)
        content_rows.append([
            t_entry[0],
            t_entry[1],
            '<a href="/mf/fc/bb/' + t_entry[0] + '/">BB View</a>',
            '<a href="/mf/fc/nav/' + t_entry[0] + '/">NAV View</a>',
            '<a target="_blank" href="{}">Reload</a>'.format(
                fc2task.get_reload_funddata_taskhandler_url(
                    p_fund_id=t_entry[0])),
            '<a href="/mf/fc/nav_str/{}/{}/">{}</a>'.format(
                t_entry[0],
                date.today().year,
                date.today().year),
            '<a target="_blank" href="{}">View</a>'.format(src_url),
        ])

    tbl_content = {
        'heads': content_head_list,
        'rows': content_rows,
    }

    args = {
        'tpl_section_title': _("HEAD_FUND_REVIEW"),
        'tbl_content': tbl_content,
    }
    return render_to_response('mf_simple_table.tpl.html', args)
Exemplo n.º 5
0
def get_year_nav_fund_list():
    #TODO: return a list of fund nav number for this year

    codename_all = FundCodeModel.get_codename_list()
    this_year = date.today().year

    fund_list = []
    for t_entry in codename_all[:10]:
        t_fund_id = t_entry[0]
        t_fundinfo = FundClearInfoModel.get_by_key_name(
            FundClearInfoModel.compose_key_name(t_fund_id))
        if t_fundinfo is None:
            fund_list.append(t_entry + [0])
        else:
            t_funddata = FundClearDataModel.all().ancestor(t_fundinfo).filter(
                'year', str(this_year)).get()
            if t_funddata is None:
                fund_list.append(t_entry + [0])
            else:
                t_nav_dict = t_funddata._get_nav_dict()
                fund_list.append(t_entry + [len(t_nav_dict)])
    return fund_list
Exemplo n.º 6
0
def get_zero_nav_fund_list():
    #TODO: return a list of fund which has no any nav for this year
    codename_all = FundCodeModel.get_codename_list()
    this_year = date.today().year

    zero_fund_list = []
    for t_entry in codename_all[:20]:
        t_fund_id = t_entry[0]
        t_fundinfo = FundClearInfoModel.get_by_key_name(
            FundClearInfoModel.compose_key_name(t_fund_id))
        if t_fundinfo is None:
            zero_fund_list.append(t_entry)
        else:
            t_funddata = FundClearDataModel.all().ancestor(t_fundinfo).filter(
                'year', str(this_year)).get()
            if t_funddata is None:
                zero_fund_list.append(t_entry)
            else:
                t_nav_dict = t_funddata._get_nav_dict()
                if len(t_nav_dict) == 0:
                    zero_fund_list.append(t_entry)

    return zero_fund_list
Exemplo n.º 7
0
def chain_update_taskhandler(request):
    '''
    function request 3 param: 
    code_index(mondatory): the start index of FundCodeModel.get_codename_list(),
    type(optional): fund data update type; <all> means update all years data
    year(optional): which year nav to download
    '''

    p_code_index = int(request.REQUEST['PARAM1'])
    p_type = ''
    p_year = date.today().year - 1
    if 'PARAM2' in request.REQUEST.keys():
        p_type = str(request.REQUEST['PARAM2'])
    if 'PARAM3' in request.REQUEST.keys():
        p_year = str(request.REQUEST['PARAM3'])

    codename_list = FundCodeModel.get_codename_list()
    #codename_list = codename_list[10:15]
    response = HttpResponse(
        'chain_update_taskhandler with code_index {code_index}'.format(
            code_index=p_code_index))
    if p_code_index < len(codename_list):
        #-> add update_funddata_task for p_code_index
        p_code = codename_list[p_code_index][0]
        taskhandler_url = os.path.dirname(
            os.path.dirname(request.get_full_path())) + '/dupdate/'
        taskqueue.add(method='GET',
                      url=taskhandler_url,
                      countdown=5,
                      params={
                          'PARAM1': p_code,
                          'PARAM2': p_year,
                          'PARAM3': p_type,
                      })
        logging.info(
            'chain_update_taskhandler: add update task for fund_id {fund_id}'.
            format(fund_id=p_code))
        #-> add chain_update_task for (p_code_index+1)
        p_next_index = p_code_index + 1
        if p_next_index < len(codename_list):
            taskqueue.add(method='GET',
                          url=os.path.dirname(request.get_full_path()) + '/',
                          countdown=50,
                          params={
                              'PARAM1': p_next_index,
                              'PARAM2': p_type,
                              'PARAM3': p_year,
                          })
            logging.info(
                'chain_update_taskhandler: add chain_update task for index {index}'
                .format(index=p_next_index))
        else:
            logging.info(
                'chain_update_taskhandler: end chain_update task with index {index}'
                .format(index=p_next_index))
            '''
            taskqueue.add(method = 'GET', 
                          url = reviewtask.get_fc_init_url(),
                          countdown = 10,
                          )
            logging.info('chain_update_taskhandler: review chain update task added.')
            '''
    else:
        logging.warning(
            'chain_update_taskhandler: code index {code_index} param error'.
            format(code_index=p_code_index))

    response.status_code = httplib.OK
    return response