<commit_before>'use strict';

var srlog = SIREPO.srlog;
var srdbg = SIREPO.srdbg;

SIREPO.USER_MANUAL_URL = 'https://ops.aps.anl.gov/manuals/elegant_latest/elegant.html';
SIREPO.USER_FORUM_URL = 'https://www3.aps.anl.gov/forums/elegant/';
SIREPO.ELEGANT_COMMAND_PREFIX = 'command_';
SIREPO.PLOTTING_COLOR_MAP = 'afmhot';
SIREPO.appImportText = 'Import an elegant command (.ele) or lattice (.lte) file';
//TODO(pjm): provide API for this, keyed by field type
SIREPO.appFieldEditors = [
    '<div data-ng-switch-when="BeamInputFile" class="col-sm-7">',
      '<div data-file-field="field" data-model="model" data-file-type="bunchFile-sourceFile" data-empty-selection-text="No File Selected"></div>',
    '</div>',
    '<div data-ng-switch-when="LatticeBeamlineList" data-ng-class="fieldClass">',
      '<div data-lattice-beamline-list="" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="ElegantLatticeList" data-ng-class="fieldClass">',
      '<div data-elegant-lattice-list="" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="InputFileXY" class="col-sm-7">',
      '<div data-input-file-x-y="" data-model-name="modelName" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="OutputFile" data-ng-class="fieldClass">',
      '<div data-output-file-field="field" data-model="model"></div>',
    '</div>',
    '<div data-ng-switch-when="RPNBoolean" data-ng-class="fieldClass">',
      '<div data-rpn-boolean="" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="RPNValue">',
      '<div data-ng-class="fieldClass">',
        '<input data-rpn-value="" data-ng-model="model[field]" class="form-control" style="text-align: right" data-lpignore="true" required />',
      '</div>',
      //TODO(pjm): fragile - hide rpnStaic value when in column mode, need better detection this case
      '<div data-ng-hide="{{ fieldSize && fieldSize != \'2\' }}" class="col-sm-2">',
        '<div data-rpn-static="" data-model="model" data-field="field"></div>',
      '</div>',
    '</div>',
    '<div data-ng-switch-when="StringArray" data-ng-class="fieldClass">',
      '<input data-ng-model="model[field]" class="form-control" data-lpignore="true" required />',
    '</div>',
    '<div data-ng-switch-when="ValueList" data-ng-class="fieldClass">',
      '<div class="form-control-static" data-ng-if="model.valueList[field].length == 1">{{ model.valueList[field][0] }}</div>',
      '<select data-ng-if="model.valueList[field].length != 1" class="form-control" data-ng-model="model[field]" data-ng-options="item as item for item in model.valueList[field]"></select>',
    '</div>',
    '<div data-ng-switch-when="FileValueList">',
      '<div data-ng-class="fieldClass">',
        '<div class="input-group">',
          '<select class="form-control" data-ng-model="model[field]" data-ng-options="item as item for item in model[\'valueList\'][field]"></select>',
            '<a href class="btn btn-default input-group-addon elegant-download-button" data-file-value-button="" data-ng-href="{{ fileDownloadURL(model) }}"><span class="glyphicon glyphicon-cloud-download"></span></a>',
        '</div>',
      '</div>',
    '</div>',
    '<div data-ng-switch-when="DistributionTypeStringArray" class="col-sm-7">',
        '<div data-enum-list="" data-field="model[field]" data-info="info" data-type-list="enum[\'DistributionType\']"></div>',
    '</div>',
    '<div data-ng-switch-when="BooleanStringArray" class="col-sm-7">',
        '<div data-enum-list="" data-field="model[field]" data-info="info" data-type-list="enum[\'Boolean\']"></div>',
    '</div>',
    '<div data-ng-switch-when="RandomizeStringArray" class="col-sm-7">',
        '<div data-enum-list="" data-field="model[field]" data-info="info" data-type-list="enum[\'Randomize\']"></div>',
    '</div>',
    '<div data-ng-switch-when="Integer3StringArray" class="col-sm-7">',
        '<div data-number-list="" data-field="model[field]" data-info="info" data-type="Integer" data-count="3"></div>',
    '</div>',
    '<div data-ng-switch-when="Integer6StringArray" class="col-sm-7">',
        '<div data-number-list="" data-field="model[field]" data-info="info" data-type="Integer" data-count="6"></div>',
    '</div>',
    '<div data-ng-switch-when="Float6StringArray" class="col-sm-7">',
        '<div data-number-list="" data-field="model[field]" data-info="info" data-type="Float" data-count="6"></div>',
    '</div>',
].join('');
SIREPO.appDownloadLinks = [
    '<li><a href data-ng-href="{{ dataFileURL(\'csv\') }}">CSV Data File</a></li>',
].join('');
SIREPO.lattice = {
    elementColor: {
        BMAPXY: 'magenta',
        FTABLE: 'magenta',
        KOCT: 'lightyellow',
        KQUAD: 'tomato',
        KSEXT: 'lightgreen',
        MATTER: 'black',
        OCTU: 'yellow',
        QUAD: 'red',
        QUFRINGE: 'salmon',
        SEXT: 'lightgreen',
        VKICK: 'blue',
        LMIRROR: 'lightblue',
        REFLECT: 'blue',
    },
    elementPic: {
        alpha: ['ALPH'],
        bend: ['BRAT', 'BUMPER', 'CSBEND', 'CSRCSBEND', 'FMULT', 'FTABLE', 'HKICK', 'KICKER', 'KPOLY', 'KSBEND', 'KQUSE', 'MBUMPER', 'MULT', 'NIBEND', 'NISEPT', 'RBEN', 'SBEN', 'TUBEND'],
        drift: ['CSRDRIFT', 'DRIF', 'EDRIFT', 'EMATRIX', 'LSCDRIFT'],
        aperture: ['CLEAN', 'ECOL', 'MAXAMP', 'RCOL', 'SCRAPER'],
        lens: ['LTHINLENS'],
        magnet: ['BMAPXY', 'KOCT', 'KQUAD', 'KSEXT', 'MATTER', 'OCTU', 'QUAD', 'QUFRINGE', 'SEXT', 'VKICK'],
        malign: ['MALIGN'],
        mirror: ['LMIRROR'],
        recirc: ['RECIRC'],
        solenoid: ['MAPSOLENOID', 'SOLE'],
        undulator: ['CORGPIPE', 'CWIGGLER', 'GFWIGGLER', 'LSRMDLTR', 'MATR', 'UKICKMAP', 'WIGGLER'],
        watch: ['HMON', 'MARK', 'MONI', 'PEPPOT', 'VMON', 'WATCH'],
        zeroLength: ['BRANCH', 'CENTER', 'CHARGE', 'DSCATTER', 'ELSE', 'EMITTANCE', 'ENERGY', 'FLOOR', 'HISTOGRAM', 'IBSCATTER', 'ILMATRIX', 'IONEFFECTS', 'MAGNIFY', 'MHISTOGRAM', 'PFILTER', 'REFLECT','REMCOR', 'RIMULT', 'ROTATE', 'SAMPLE', 'SCATTER', 'SCMULT', 'SCRIPT', 'SLICE', 'SREFFECTS', 'STRAY', 'TFBDRIVER', 'TFBPICKUP', 'TRCOUNT', 'TRWAKE', 'TWISS', 'WAKE', 'ZLONGIT', 'ZTRANSVERSE'],
        rf: ['CEPL', 'FRFMODE', 'FTRFMODE', 'MODRF', 'MRFDF', 'RAMPP', 'RAMPRF', 'RFCA', 'RFCW', 'RFDF', 'RFMODE', 'RFTM110', 'RFTMEZ0', 'RMDF', 'TMCF', 'TRFMODE', 'TWLA', 'TWMTA', 'TWPL'],
    },
};

SIREPO.app.factory('elegantService', function(appState, requestSender, rpnService, $rootScope) {
    var self = {};
    var filenameRequired = ['command_floor_coordinates', 'HISTOGRAM', 'SLICE', 'WATCH'];<commit_msg>elegant: kickers steer beam but do not affect floor coords<commit_after>'use strict';

var srlog = SIREPO.srlog;
var srdbg = SIREPO.srdbg;

SIREPO.USER_MANUAL_URL = 'https://ops.aps.anl.gov/manuals/elegant_latest/elegant.html';
SIREPO.USER_FORUM_URL = 'https://www3.aps.anl.gov/forums/elegant/';
SIREPO.ELEGANT_COMMAND_PREFIX = 'command_';
SIREPO.PLOTTING_COLOR_MAP = 'afmhot';
SIREPO.appImportText = 'Import an elegant command (.ele) or lattice (.lte) file';
//TODO(pjm): provide API for this, keyed by field type
SIREPO.appFieldEditors = [
    '<div data-ng-switch-when="BeamInputFile" class="col-sm-7">',
      '<div data-file-field="field" data-model="model" data-file-type="bunchFile-sourceFile" data-empty-selection-text="No File Selected"></div>',
    '</div>',
    '<div data-ng-switch-when="LatticeBeamlineList" data-ng-class="fieldClass">',
      '<div data-lattice-beamline-list="" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="ElegantLatticeList" data-ng-class="fieldClass">',
      '<div data-elegant-lattice-list="" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="InputFileXY" class="col-sm-7">',
      '<div data-input-file-x-y="" data-model-name="modelName" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="OutputFile" data-ng-class="fieldClass">',
      '<div data-output-file-field="field" data-model="model"></div>',
    '</div>',
    '<div data-ng-switch-when="RPNBoolean" data-ng-class="fieldClass">',
      '<div data-rpn-boolean="" data-model="model" data-field="field"></div>',
    '</div>',
    '<div data-ng-switch-when="RPNValue">',
      '<div data-ng-class="fieldClass">',
        '<input data-rpn-value="" data-ng-model="model[field]" class="form-control" style="text-align: right" data-lpignore="true" required />',
      '</div>',
      //TODO(pjm): fragile - hide rpnStaic value when in column mode, need better detection this case
      '<div data-ng-hide="{{ fieldSize && fieldSize != \'2\' }}" class="col-sm-2">',
        '<div data-rpn-static="" data-model="model" data-field="field"></div>',
      '</div>',
    '</div>',
    '<div data-ng-switch-when="StringArray" data-ng-class="fieldClass">',
      '<input data-ng-model="model[field]" class="form-control" data-lpignore="true" required />',
    '</div>',
    '<div data-ng-switch-when="ValueList" data-ng-class="fieldClass">',
      '<div class="form-control-static" data-ng-if="model.valueList[field].length == 1">{{ model.valueList[field][0] }}</div>',
      '<select data-ng-if="model.valueList[field].length != 1" class="form-control" data-ng-model="model[field]" data-ng-options="item as item for item in model.valueList[field]"></select>',
    '</div>',
    '<div data-ng-switch-when="FileValueList">',
      '<div data-ng-class="fieldClass">',
        '<div class="input-group">',
          '<select class="form-control" data-ng-model="model[field]" data-ng-options="item as item for item in model[\'valueList\'][field]"></select>',
            '<a href class="btn btn-default input-group-addon elegant-download-button" data-file-value-button="" data-ng-href="{{ fileDownloadURL(model) }}"><span class="glyphicon glyphicon-cloud-download"></span></a>',
        '</div>',
      '</div>',
    '</div>',
    '<div data-ng-switch-when="DistributionTypeStringArray" class="col-sm-7">',
        '<div data-enum-list="" data-field="model[field]" data-info="info" data-type-list="enum[\'DistributionType\']"></div>',
    '</div>',
    '<div data-ng-switch-when="BooleanStringArray" class="col-sm-7">',
        '<div data-enum-list="" data-field="model[field]" data-info="info" data-type-list="enum[\'Boolean\']"></div>',
    '</div>',
    '<div data-ng-switch-when="RandomizeStringArray" class="col-sm-7">',
        '<div data-enum-list="" data-field="model[field]" data-info="info" data-type-list="enum[\'Randomize\']"></div>',
    '</div>',
    '<div data-ng-switch-when="Integer3StringArray" class="col-sm-7">',
        '<div data-number-list="" data-field="model[field]" data-info="info" data-type="Integer" data-count="3"></div>',
    '</div>',
    '<div data-ng-switch-when="Integer6StringArray" class="col-sm-7">',
        '<div data-number-list="" data-field="model[field]" data-info="info" data-type="Integer" data-count="6"></div>',
    '</div>',
    '<div data-ng-switch-when="Float6StringArray" class="col-sm-7">',
        '<div data-number-list="" data-field="model[field]" data-info="info" data-type="Float" data-count="6"></div>',
    '</div>',
].join('');
SIREPO.appDownloadLinks = [
    '<li><a href data-ng-href="{{ dataFileURL(\'csv\') }}">CSV Data File</a></li>',
].join('');
SIREPO.lattice = {
    elementColor: {
        BMAPXY: 'magenta',
        FTABLE: 'magenta',
        KOCT: 'lightyellow',
        KQUAD: 'tomato',
        KSEXT: 'lightgreen',
        MATTER: 'black',
        OCTU: 'yellow',
        QUAD: 'red',
        QUFRINGE: 'salmon',
        SEXT: 'lightgreen',
        VKICK: 'blue',
        LMIRROR: 'lightblue',
        REFLECT: 'blue',
    },
    elementPic: {
        alpha: ['ALPH'],
        bend: ['BRAT', 'BUMPER', 'CSBEND', 'CSRCSBEND', 'FMULT', 'FTABLE', 'KPOLY', 'KSBEND', 'KQUSE', 'MBUMPER', 'MULT', 'NIBEND', 'NISEPT', 'RBEN', 'SBEN', 'TUBEND'],
        drift: ['CSRDRIFT', 'DRIF', 'EDRIFT', 'EMATRIX', 'LSCDRIFT'],
        aperture: ['CLEAN', 'ECOL', 'MAXAMP', 'RCOL', 'SCRAPER'],
        lens: ['LTHINLENS'],
        magnet: ['BMAPXY', 'HKICK', 'KICKER', 'KOCT', 'KQUAD', 'KSEXT', 'MATTER', 'OCTU', 'QUAD', 'QUFRINGE', 'SEXT', 'VKICK'],
        malign: ['MALIGN'],
        mirror: ['LMIRROR'],
        recirc: ['RECIRC'],
        solenoid: ['MAPSOLENOID', 'SOLE'],
        undulator: ['CORGPIPE', 'CWIGGLER', 'GFWIGGLER', 'LSRMDLTR', 'MATR', 'UKICKMAP', 'WIGGLER'],
        watch: ['HMON', 'MARK', 'MONI', 'PEPPOT', 'VMON', 'WATCH'],
        zeroLength: ['BRANCH', 'CENTER', 'CHARGE', 'DSCATTER', 'ELSE', 'EMITTANCE', 'ENERGY', 'FLOOR', 'HISTOGRAM', 'IBSCATTER', 'ILMATRIX', 'IONEFFECTS', 'MAGNIFY', 'MHISTOGRAM', 'PFILTER', 'REFLECT','REMCOR', 'RIMULT', 'ROTATE', 'SAMPLE', 'SCATTER', 'SCMULT', 'SCRIPT', 'SLICE', 'SREFFECTS', 'STRAY', 'TFBDRIVER', 'TFBPICKUP', 'TRCOUNT', 'TRWAKE', 'TWISS', 'WAKE', 'ZLONGIT', 'ZTRANSVERSE'],
        rf: ['CEPL', 'FRFMODE', 'FTRFMODE', 'MODRF', 'MRFDF', 'RAMPP', 'RAMPRF', 'RFCA', 'RFCW', 'RFDF', 'RFMODE', 'RFTM110', 'RFTMEZ0', 'RMDF', 'TMCF', 'TRFMODE', 'TWLA', 'TWMTA', 'TWPL'],
    },
};

SIREPO.app.factory('elegantService', function(appState, requestSender, rpnService, $rootScope) {
    var self = {};
    var filenameRequired = ['command_floor_coordinates', 'HISTOGRAM', 'SLICE', 'WATCH'];
{'fraction_non_alphanumeric': 0.23506095280831651, 'fraction_numerical': 0.0035898586493156833, 'mean_word_length': 4.038432554634514, 'pattern_counts': {'":': 0, '<': 167, '<?xml version=': 0, '>': 167, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7137190', 'n_tokens_mistral': 4914, 'n_tokens_neox': 5004, 'n_words': 850}