<commit_before>#!/usr/bin/python

import os, glob, random

import flask
from flask import request, render_template, send_from_directory, current_app, session as current_session, jsonify
from manga_utils import generalUtils as gu
from collections import OrderedDict

from ..model.database import db
from ..utilities import setGlobalVersion,getImages
from ..jinja_filters import getMPL

import sdss.internal.database.utah.mangadb.DataModelClasses as datadb

try:
    from . import valueFromRequest,processRequest
except ValueError:
    pass
    
    
index_page = flask.Blueprint("index_page", __name__)

@index_page.route('/marvin/setversion', methods=['GET','POST'])
@index_page.route('/setversion', methods=['GET','POST'])
def setVersion():
    ''' Set version to use during MaNGA SAS '''
    
    # get form    
    verform = processRequest(request=request)

    # set version mode
    current_session['vermode'] = 'MPL' if verform['vermode']=='mpl' else 'DRP/DAP'
    
    # set version
    if verform['vermode']=='mpl':
        mpl = getMPL(verform['mplver'])
        drpver,dapver = mpl.split(':')[1].strip().split(', ')
        current_session['currentver'] = drpver
        current_session['currentdapver'] = dapver if dapver != 'NA' else None
        current_session['currentmpl'] = verform['mplver']
    else:
        current_session['currentver'] = verform['version']
        current_session['currentdapver'] = verform['dapversion']
        current_session['currentmpl'] = verform['mplver']
        
    print(current_session['currentver'],current_session['currentdapver'],current_session['currentmpl'])

    return jsonify(result='set the version')

@index_page.route('/', methods=['GET'])
@index_page.route('/index', methods=['GET'])
@index_page.route('/index.html', methods=['GET'])
@index_page.route('/marvin/index.html', methods=['GET'])
def index():
    ''' Documentation here. '''
    
    session = db.Session()    
    index = {}
    index['title'] = "Marvin"
    
    # set global version
    setGlobalVersion()
    version = current_session['currentver']
    
    current_app.logger.info('Loading index page...')
    
    # find and grab all images ; convert paths to sas paths
    current_app.logger.info('Building image list...')
    redux = os.path.join(os.getenv('MANGA_SPECTRO_REDUX'),version)
    good = os.path.isdir(redux)
    index['good'] = good
    images = getImages(version=version)

    # get versions
    current_session['marvinver'] = gu.getMangaVersion(marvin=True)
    current_session['sdssver'] = gu.getMangaVersion(sdss=True)
    current_session['drpver'] = gu.getMangaVersion(drp=True)

    if any(images):        
        # randomize the images
        current_app.logger.info('Selecting 100 random images...')
        if len(images) < 100: biglist = [random.choice(images) for i in xrange(100)]
        else: biglist = random.sample(images,100)
        images = biglist

        # make unique image dictionary
        current_app.logger.info('Building image dictionary...')<commit_msg>added try-catch for current.py error; diagnosing setSessionDAP error; started expanding footer template<commit_after>#!/usr/bin/python

import os, glob, random

import flask
from flask import request, render_template, send_from_directory, current_app, session as current_session, jsonify
from manga_utils import generalUtils as gu
from collections import OrderedDict

from ..model.database import db
from ..utilities import setGlobalVersion,getImages
from ..jinja_filters import getMPL

import sdss.internal.database.utah.mangadb.DataModelClasses as datadb

try:
    from . import valueFromRequest,processRequest
except ValueError:
    pass
    
    
index_page = flask.Blueprint("index_page", __name__)

@index_page.route('/marvin/setversion', methods=['GET','POST'])
@index_page.route('/setversion', methods=['GET','POST'])
def setVersion():
    ''' Set version to use during MaNGA SAS '''
    
    # get form    
    verform = processRequest(request=request)

    # set version mode
    current_session['vermode'] = 'MPL' if verform['vermode']=='mpl' else 'DRP/DAP'
    
    # set version
    if verform['vermode']=='mpl':
        mpl = getMPL(verform['mplver'])
        drpver,dapver = mpl.split(':')[1].strip().split(', ')
        current_session['currentver'] = drpver
        current_session['currentdapver'] = dapver if dapver != 'NA' else None
        current_session['currentmpl'] = verform['mplver']
    else:
        current_session['currentver'] = verform['version']
        current_session['currentdapver'] = verform['dapversion']
        current_session['currentmpl'] = verform['mplver']
        
    print(current_session['currentver'],current_session['currentdapver'],current_session['currentmpl'])

    return jsonify(result='set the version')

@index_page.route('/', methods=['GET'])
@index_page.route('/index', methods=['GET'])
@index_page.route('/index.html', methods=['GET'])
@index_page.route('/marvin/index.html', methods=['GET'])
def index():
    ''' Documentation here. '''
    
    session = db.Session()    
    index = {}
    index['title'] = "Marvin"
    
    # set global version
    setGlobalVersion()
    version = current_session['currentver']
    
    current_app.logger.info('Loading index page...')
    
    # find and grab all images ; convert paths to sas paths
    current_app.logger.info('Building image list...')
    redux = os.path.join(os.getenv('MANGA_SPECTRO_REDUX'),version)
    good = os.path.isdir(redux)
    index['good'] = good
    images = getImages(version=version)

    # get versions
    try: current_session['marvinver'] = gu.getMangaVersion(marvin=True)
    except TypeError as e:
        current_session['marvinver'] = None
    try: current_session['sdssver'] = gu.getMangaVersion(sdss=True)
    except TypeError as e:
        current_session['sdssver'] = None
    try: current_session['drpver'] = gu.getMangaVersion(drp=True)
    except TypeError as e:
        current_session['drpver'] = None        
    
    if any(images):        
        # randomize the images
        current_app.logger.info('Selecting 100 random images...')
        if len(images) < 100: biglist = [random.choice(images) for i in xrange(100)]
        else: biglist = random.sample(images,100)
        images = biglist

        # make unique image dictionary
        current_app.logger.info('Building image dictionary...')
{'fraction_non_alphanumeric': 0.13394955350148832, 'fraction_numerical': 0.004073319755600814, 'mean_word_length': 3.7570789865871834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4769433', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1913, 'n_words': 423}