<commit_before>from __future__ import print_function

import logging

from ophyd.controls import EpicsSignal
from ophyd.controls.signal import SignalGroup


class GasSwitcher(SignalGroup):
    '''Base class for Gas Switcher'''

    def __init__(self, *args, **kwargs):
        super(GasSwitcher, self).__init__(*args, **kwargs)

    def current_pos(self):
        pass

    def requested_pos(self):
        pass


class XPDGasSwitcher(GasSwitcher):
    def __init__(self, requested_pos=None, current_pos=None):
       GasSwitcher.__init__(self)
       signals = [EpicsSignal(current_pos, rw=False, alias='_current_pos'),
                  EpicsSignal(requested_pos, alias='_requested_pos'),
                  ] 

       for sig in signals:
           self.add_signal(sig)

    @property
    def current_pos(self):
        return self._current_pos.value

    @property
    def requested_pos(self):
        return self._requested_pos.value

    @requested_pos.setter
    def requested_pos(self, val):
        self._requested_pos.value = val


gas1 = XPDGasSwitcher(requested_pos='XF:28IDC-ES:1{Env:02}Pos-SP',
        current_pos='XF:28IDC-ES:1{Env:02}Pos-I')
<commit_msg>Added functionality for working with gas by name in gas_switcher<commit_after>from __future__ import print_function

import logging

from ophyd.controls import EpicsSignal
from ophyd.controls.signal import SignalGroup


class GasSwitcher(SignalGroup):
    '''Base class for Gas Switcher'''

    def __init__(self, *args, **kwargs):
        super(GasSwitcher, self).__init__(*args, **kwargs)

    def current_pos(self):
        pass

    def requested_pos(self):
        pass


class XPDGasSwitcher(GasSwitcher):
    def __init__(self, requested_pos=None, current_pos=None, gasdict = {}):
       GasSwitcher.__init__(self)
       signals = [EpicsSignal(current_pos, rw=False, alias='_current_pos'),
                  EpicsSignal(requested_pos, alias='_requested_pos'),
                  ] 
       self._gasdict = gasdict
       for sig in signals:
           self.add_signal(sig)
       return


    @property
    def current_pos(self):
        return self._current_pos.value


    @property
    def requested_pos(self):
        return self._requested_pos.value


    @requested_pos.setter
    def requested_pos(self, val):
        self._requested_pos.value = val
        return


    def define_gas(self, gas, n):
        self._gasdict[n] = gas
        return


    def print_gasses(self):
        print('Gas positions are defined as follows:')
        print('-------------------------------------')
        for k, v in self._gasdict.items():
            print(k, '-', v)
        print('-------------------------------------')
        print('switch(\'gas\') -> switch to \'gas\'')
        print('define_gas(\'gas\', n) -> define \'gas\' to be at position n')
        return


    def switch(self, newgas):
        if not newgas in self._gasdict.values():
            print(gas, 'has not been defined.')
            return
        gas_nums = [n for n, gas in self._gasdict.items() if gas == newgas]
        if len(gas_nums) > 1:
            print('Error: more than one position has been defined for this gas')
            return
        self.requested_pos = gas_nums[0]
        return


    def print_curr_gas(self): 
        print('Current gas is:')
        print(self._gasdict[self.current_pos])
        return



{'fraction_non_alphanumeric': 0.12381796690307328, 'fraction_numerical': 0.0038416075650118202, 'mean_word_length': 2.4157416750756813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6874209', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1013, 'n_words': 240}