Best Python code snippet using lemoncheesecake
763d4b211ec9_fixing_audit_fk.py
Source:763d4b211ec9_fixing_audit_fk.py  
1# -*- coding: utf-8 -*-2"""fixing audit fk3Revision ID: 763d4b211ec94Revises: d2424a248d635Create Date: 2016-03-24 14:13:44.8177236"""7# revision identifiers, used by Alembic.8revision = '763d4b211ec9'9down_revision = 'd2424a248d63'10from alembic import op11import sqlalchemy as sa12def upgrade():13    op.add_column('metrics', sa.Column('changed_by_fk', sa.Integer(), nullable=True))14    op.add_column('metrics', sa.Column('changed_on', sa.DateTime(), nullable=True))15    op.add_column('metrics', sa.Column('created_by_fk', sa.Integer(), nullable=True))16    op.add_column('metrics', sa.Column('created_on', sa.DateTime(), nullable=True))17    try:18        op.alter_column('columns', 'changed_on',19                   existing_type=sa.DATETIME(),20                   nullable=True)21        op.alter_column('columns', 'created_on',22                   existing_type=sa.DATETIME(),23                   nullable=True)24        op.alter_column('css_templates', 'changed_on',25                   existing_type=sa.DATETIME(),26                   nullable=True)27        op.alter_column('css_templates', 'created_on',28                   existing_type=sa.DATETIME(),29                   nullable=True)30        op.alter_column('dashboards', 'changed_on',31                   existing_type=sa.DATETIME(),32                   nullable=True)33        op.alter_column('dashboards', 'created_on',34                   existing_type=sa.DATETIME(),35                   nullable=True)36        op.alter_column('datasources', 'changed_by_fk',37                   existing_type=sa.INTEGER(),38                   nullable=True)39        op.alter_column('datasources', 'changed_on',40                   existing_type=sa.DATETIME(),41                   nullable=True)42        op.alter_column('datasources', 'created_by_fk',43                   existing_type=sa.INTEGER(),44                   nullable=True)45        op.alter_column('datasources', 'created_on',46                   existing_type=sa.DATETIME(),47                   nullable=True)48        op.alter_column('dbs', 'changed_on',49                   existing_type=sa.DATETIME(),50                   nullable=True)51        op.alter_column('dbs', 'created_on',52                   existing_type=sa.DATETIME(),53                   nullable=True)54        op.alter_column('slices', 'changed_on',55                   existing_type=sa.DATETIME(),56                   nullable=True)57        op.alter_column('slices', 'created_on',58                   existing_type=sa.DATETIME(),59                   nullable=True)60        op.alter_column('sql_metrics', 'changed_on',61                   existing_type=sa.DATETIME(),62                   nullable=True)63        op.alter_column('sql_metrics', 'created_on',64                   existing_type=sa.DATETIME(),65                   nullable=True)66        op.alter_column('table_columns', 'changed_on',67                   existing_type=sa.DATETIME(),68                   nullable=True)69        op.alter_column('table_columns', 'created_on',70                   existing_type=sa.DATETIME(),71                   nullable=True)72        op.alter_column('tables', 'changed_on',73                   existing_type=sa.DATETIME(),74                   nullable=True)75        op.alter_column('tables', 'created_on',76                   existing_type=sa.DATETIME(),77                   nullable=True)78        op.alter_column('url', 'changed_on',79                   existing_type=sa.DATETIME(),80                   nullable=True)81        op.alter_column('url', 'created_on',82                   existing_type=sa.DATETIME(),83                   nullable=True)84        op.create_foreign_key(None, 'metrics', 'ab_user', ['changed_by_fk'], ['id'])85        op.create_foreign_key(None, 'metrics', 'ab_user', ['created_by_fk'], ['id'])86    except:87        pass88def downgrade():89    op.drop_column('metrics', 'created_on')90    op.drop_column('metrics', 'created_by_fk')91    op.drop_column('metrics', 'changed_on')92    op.drop_column('metrics', 'changed_by_fk')93    try:94        op.alter_column('url', 'created_on',95                   existing_type=sa.DATETIME(),96                   nullable=False)97        op.alter_column('url', 'changed_on',98                   existing_type=sa.DATETIME(),99                   nullable=False)100        op.alter_column('tables', 'created_on',101                   existing_type=sa.DATETIME(),102                   nullable=False)103        op.alter_column('tables', 'changed_on',104                   existing_type=sa.DATETIME(),105                   nullable=False)106        op.alter_column('table_columns', 'created_on',107                   existing_type=sa.DATETIME(),108                   nullable=False)109        op.alter_column('table_columns', 'changed_on',110                   existing_type=sa.DATETIME(),111                   nullable=False)112        op.alter_column('sql_metrics', 'created_on',113                   existing_type=sa.DATETIME(),114                   nullable=False)115        op.alter_column('sql_metrics', 'changed_on',116                   existing_type=sa.DATETIME(),117                   nullable=False)118        op.alter_column('slices', 'created_on',119                   existing_type=sa.DATETIME(),120                   nullable=False)121        op.alter_column('slices', 'changed_on',122                   existing_type=sa.DATETIME(),123                   nullable=False)124        op.drop_constraint(None, 'metrics', type_='foreignkey')125        op.drop_constraint(None, 'metrics', type_='foreignkey')126        op.alter_column('dbs', 'created_on',127                   existing_type=sa.DATETIME(),128                   nullable=False)129        op.alter_column('dbs', 'changed_on',130                   existing_type=sa.DATETIME(),131                   nullable=False)132        op.alter_column('datasources', 'created_on',133                   existing_type=sa.DATETIME(),134                   nullable=False)135        op.alter_column('datasources', 'created_by_fk',136                   existing_type=sa.INTEGER(),137                   nullable=False)138        op.alter_column('datasources', 'changed_on',139                   existing_type=sa.DATETIME(),140                   nullable=False)141        op.alter_column('datasources', 'changed_by_fk',142                   existing_type=sa.INTEGER(),143                   nullable=False)144        op.alter_column('dashboards', 'created_on',145                   existing_type=sa.DATETIME(),146                   nullable=False)147        op.alter_column('dashboards', 'changed_on',148                   existing_type=sa.DATETIME(),149                   nullable=False)150        op.alter_column('css_templates', 'created_on',151                   existing_type=sa.DATETIME(),152                   nullable=False)153        op.alter_column('css_templates', 'changed_on',154                   existing_type=sa.DATETIME(),155                   nullable=False)156        op.alter_column('columns', 'created_on',157                   existing_type=sa.DATETIME(),158                   nullable=False)159        op.alter_column('columns', 'changed_on',160                   existing_type=sa.DATETIME(),161                   nullable=False)162    except:...__main__.py
Source:__main__.py  
1from covid19.models.inception import InceptionTimePlus172from .experiment import Experiment3from .experiments_set import ExperimentSet4import calendar5from covid19.models import Transformer6from tsai.models.InceptionTimePlus import InceptionTimePlus17x17, InceptionTimePlus62x627from tsai.models.TST import TST8from tsai.models.RNNPlus import GRUPlus, LSTMPlus9from covid19.datasets.open_world import OpenWorldDataset10class LSTMPlus1(LSTMPlus):11    def __init__(self, args, **kwargs):12        super(LSTMPlus1, self).__init__(*args, **kwargs, hidden_size=512)13if __name__ == "__main__":14    # d = OpenWorldDataset()15    # d.filter_country(['Ukraine'])16    # print(d._dataframe)17    e = ExperimentSet(18        models=[19            # LSTMPlus,20            # GRUPlus21            # TST,22            InceptionTimePlus17x1723        ],24        lr=[1e-1],25        early_stop_patience=100,26        # epochs=100000,27        epochs=100,28        features=[29            # ['total_cases_per_million_std', 'new_cases_per_million_std'], #0.16075830            # ['total_cases_per_population_std'],31            # ['total_cases_std', 'new_cases_std'] # 0.46210532            # ['new_cases_smoothed_nx'], 0.87770133            # ['total_cases_per_million_std'] # 0.2090466767549514834            # ['total_cases_per_population', 'new_cases_per_population'] # 0.13119635            # ['total_cases_per_population', 'new_cases_per_population', 'non_sick_per_population'], #0.29309836            # [37            #     'total_cases_per_population',38            #     'new_cases_per_population',39            #     'non_sick_per_population',40            #     'people_vaccinated_per_population'41            # ],42            [43                'total_cases_nx', 'new_cases_nx', 'new_vaccinations_nx',44                'people_fully_vaccinated_nx', 'new_deaths_nx'45                # 'new_cases_smoothed_nx',46                # 'total_cases_per_population_std',47                # 'new_cases_per_population_std',48                # 'non_sick_per_population_std',49                # 'people_vaccinated_per_population_std',50                # 'people_fully_vaccinated_per_population_std',51                # 'new_vaccinations_per_population_std'52            ] + list(calendar.day_name),53            # ['existing_nx'],54            # ['existing_std', 'confirmed_std', 'delta_existing_std'] + list(calendar.day_name),55            # ['existing_pop', 'confirmed_pop', 'none_sick_pop', 'delta_existing_pop'],56            # ['existing_pop', 'confirmed_pop', 'none_sick_pop', 'delta_existing_pop'] + list(calendar.day_name)57            # ['delta_existing_norm'],58            # ['delta_existing_nx'],59            # ['delta_existing_std'],Ë60            # ['existing_std_all', 'confirmed_std_all', 'delta_confirmed_std_all', 'delta_recovered_std_all'] + list(calendar.day_name),61            # ['existing_std', 'delta_existing_std'],62            # ['existing_std_all', 'delta_existing_std_all'],63            # ['existing_norm', 'delta_existing_norm'],64            # ['existing_norm_all', 'delta_existing_norm_all'],65            # ['delta_existing_nx'],66            # ['existing_nx', 'delta_existing_nx'],67            # ['existing_std', 'delta_existing_std'],68            # ['existing_norm', 'delta_existing_norm'],69            # ['existing_rob', 'delta_existing_rob'],70            #71            # ['existing_nx_all', 'delta_existing_nx_all'],72            # ['existing_std_all', 'delta_existing_std_all'],73            # ['existing_norm_all', 'delta_existing_norm_all'],74            # ['existing_rob_all', 'delta_existing_rob_all'],75        ],76        targets=[77            # ['new_cases_origin']78            # ['new_cases_std'],79            # ['total_cases_per_population_std'],80            ['new_cases_origin']81            # ['new_cases_std']82            # ['existing_std'],83            # ['existing_nx'],84            # ['delta_existing_std'],85            # ['delta_confirmed_nx'],86            # ['delta_existing_nx']87        ],88        window=[14], #list(7 * h for h in range(1, 30)),89        horizon=[7], #list(7 * h for h in range(1, 20)),90        batch_size=[64],91        country_filter=[92            # ['United States', 'Italy', 'France', 'Germany', 'United Kingdom', 'Australia', 'Canada'],93            # ['Italy'],94            # ['France'],95            ['United States'],96        ],97        # country_filter=[['Ukraine']],98        # region_filter=[['Kyiv']],99        region_filter=[None],100        runs=1,101        do_predict=False102    )...wp-user-avatar-user.js
Source:wp-user-avatar-user.js  
1jQuery(function($) {2  // Add enctype to form with JavaScript as backup3  $('#your-profile').attr('enctype', 'multipart/form-data');4  // Store WP User Avatar ID5  var wpuaID = $('#wp-user-avatar').val();6  // Store WP User Avatar src7  var wpuaSrc = $('#wpua-preview').find('img').attr('src');8  // Remove WP User Avatar9  $('body').on('click', '#wpua-remove', function(e) {10    e.preventDefault();11    $('#wpua-original').remove();12    $('#wpua-remove-button, #wpua-thumbnail').hide();13    $('#wpua-preview').find('img:first').hide();14    $('#wpua-preview').prepend('<img id="wpua-original" />');15    $('#wpua-original').attr('src', wpua_custom.avatar_thumb);16    $('#wp-user-avatar').val("");17    $('#wpua-original, #wpua-undo-button').show();18    $('#wp_user_avatar_radio').trigger('click');19  });20  // Undo WP User Avatar21  $('body').on('click', '#wpua-undo', function(e) {22    e.preventDefault();23    $('#wpua-original').remove();24    $('#wpua-images').removeAttr('style');25    $('#wpua-undo-button').hide();26    $('#wpua-remove-button, #wpua-thumbnail').show();27    $('#wpua-preview').find('img:first').attr('src', wpuaSrc).show();28    $('#wp-user-avatar').val(wpuaID);29    $('#wp_user_avatar_radio').trigger('click');30  });31  32  // Store WP Existing User Avatar ID33  var wpuaEID = $('#wp-user-avatar-existing').val();34  // Store WP Existing User Avatar src35  var wpuaESrc = $('#wpua-preview-existing').find('img').attr('src');36  $('#wpua-undo-button-existing').hide();37  // Remove WP Existing User Avatar38  $('body').on('click', '#wpua-remove-existing', function(e) {39    e.preventDefault();40    $('#wpua-original-existing').remove();41    $('#wpua-remove-button-existing, #wpua-thumbnail-existing').hide();42    $('#wpua-preview-existing').find('img:first').hide();43    $('#wpua-preview-existing').prepend('<img id="wpua-original-existing" />');44    $('#wpua-original-existing').attr('src', wpua_custom.avatar_thumb);45    $('#wp-user-avatar-existing').val("");46    $('#wpua-original-existing, #wpua-undo-button-existing').show();47    $('#wp_user_avatar_radio-existing').trigger('click');48  });49  // Undo WP Existing User Avatar50  $('body').on('click', '#wpua-undo-existing', function(e) {51    e.preventDefault();52    $('#wpua-original-existing').remove();53    $('#wpua-images-existing').removeAttr('style');54    $('#wpua-undo-button-existing').hide();55    $('#wpua-remove-button-existing, #wpua-thumbnail-existing').show();56    $('#wpua-preview-existing').find('img:first').attr('src', wpuaSrc).show();57    $('#wp-user-avatar-existing').val(wpuaID);58    $('#wp_user_avatar_radio-existing').trigger('click');59  });...datatypes.py
Source:datatypes.py  
1'''2'''3class MultiValuedDict(object):4    ''' Store a mapping from keys to multiple values with minimal overhead.5    Avoids storing empty collecctions.6    '''7    def __init__(self):8        '''9        '''10        self._dict = dict()11    def add_value(self, key, value):12        '''13        '''14        if key is None:15            raise ValueError("Key is None")16        if value is None:17            raise ValueError("Can't put None in this dict")18        if isinstance(value, set):19            raise ValueError("Can't put sets in this dict")20        existing = self._dict.get(key)21        if existing is None:22            self._dict[key] = value23        elif isinstance(existing, set):24            existing.add(value)25        else:26            self._dict[key] = set([existing, value])27    def get_all(self, k):28        '''29        '''30        existing = self._dict.get(k)31        if existing is None:32            return []33        elif isinstance(existing, set):34            return list(existing)35        else:36            return [existing]37    def get_one(self, k, duplicate_error):38        '''39        '''40        existing = self._dict.get(k)41        if isinstance(existing, set):42            if len(existing) == 1:43                return next(iter(existing))44            else:45                raise ValueError(duplicate_error + (": %r" % (existing)))46        else:47            return existing48    def remove_value(self, key, value):49        '''50        '''51        if key is None:52            raise ValueError("Key is None")53        existing = self._dict.get(key)54        if isinstance(existing, set):55            existing.discard(value)56            if len(existing) == 0:57                del self._dict[key]58        elif existing == value:59            del self._dict[key]60        else:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
