text stringlengths 957 885k |
|---|
from __future__ import division
import Test_internal_clashscore
import os,sys
'''
Collect clash information from PROBE in resraints_manager
and compare them
'''
def get_files_data():
'''() -> list,list
reads files
RM_clash_results
PROBE_clash_results
in folder: C:\Phenix\Dev\Work\work\Clashes\junk
Returns:
RM_clash_dict,PROBE_clash_dict : two dictionaries containing the clash
information from PROBE and resraints_manager
clash_in_both,clash_only_MR,clash_only_PROBE : sets of clash keys
'''
RM_clash_results = open('RM_clash_results','r').read().splitlines()
PROBE_clash_results = open('PROBE_clash_results','r').read().splitlines()
#
RM_clash_dict = {}
PROBE_clash_dict = {}
clash_in_both = set()
clash_only_MR = set()
clash_only_PROBE = set()
clash_MR = set()
clash_PROBE = set()
#
for x in RM_clash_results:
x = x.split('::')
RM_clash_dict[x[0]] = [float(x[1]),float(x[2])]
clash_MR.add(x[0])
for x in PROBE_clash_results:
x = x.split('::')
PROBE_clash_dict[x[0]] = float(x[1])
clash_PROBE.add(x[0])
#
clash_in_both = clash_MR.intersection(clash_PROBE)
clash_only_MR = clash_MR - clash_PROBE
clash_only_PROBE = clash_PROBE - clash_MR
return RM_clash_dict,PROBE_clash_dict,clash_in_both,clash_only_MR,clash_only_PROBE
if __name__=='__main__':
currentpath = os.getcwd()
workpath = 'c:\\Phenix\\Dev\\Work\\work\\Clashes\\junk'
os.chdir(workpath)
#
file_name = sys.argv[1]
file_name = Test_internal_clashscore.get_new_file_name(file_name)
nb_clashscore,clashscore_probe,time_internal,time_probe = Test_internal_clashscore.call_both_clashscores(file_name)
output_file_name = Test_internal_clashscore.get_file_name(file_name)
#
RM_clash_dict,PROBE_clash_dict,clash_in_both,clash_only_MR,clash_only_PROBE = get_files_data()
# Print clashes that are only in one of the methods:
print '\nClash info for: {}'.format(output_file_name)
print '='*80
print 'nonbonded_clashscore: {0:.3f}'.format(nb_clashscore[1])
print 'clashscore : {0:.3f}'.format(clashscore_probe)
print '='*80
print 'Clashes that show up only in PROBE'
print '-'*80
for rec in clash_only_PROBE:
print '{0:30}{1:^14.3f}'.format(rec,PROBE_clash_dict[rec])
print '='*80
print 'Clashes that show up only in restraints_manager'
print 'Note: those clashes do not include clashes due to symmetry operations'
print '-'*80
for rec in clash_only_MR:
print '{0:30}{1:^14.3f}'.format(rec,RM_clash_dict[rec][0])
print '='*80
#
print 'Clashes in both'
outstr = '{0:30}{1:^14.3f}{2:^14.3f}{3:^14.3f}{4:^14.3f}'
print '{0:30}{1:^14}{2:^14}{3:^14}{4:^14}'.format('Clash','overlap RM','overlap RPROBE','diff','vdw')
print '-'*80
for rec in clash_in_both:
overlap_RM = RM_clash_dict[rec][0]
vdw_RM = RM_clash_dict[rec][1]
overlap_PROBE = PROBE_clash_dict[rec]
print outstr.format(rec,overlap_RM,overlap_PROBE,overlap_RM-overlap_PROBE,vdw_RM)
print '='*80
#
os.chdir(currentpath)
print 'Done' |
<gh_stars>0
import os
import json
import argparse
import logging
import datetime
import shutil
import sys
import six
from colorlog import ColoredFormatter
def _setup_logging(verbosity):
"""
Setup logging with desired verbosity
:param verbosity:
:return:
"""
logging.getLogger("dirtools").setLevel(logging.WARNING)
logger = logging.getLogger()
LOGFORMAT = '%(log_color)s%(asctime)s%(reset)s | %(log_color)s%(name)-12s %(levelname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s'
LOGCOLOUR = {
'DEBUG': 'blue',
'INFO': 'green',
'WARNING': 'orange',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
}
formatter = ColoredFormatter(LOGFORMAT, log_colors=LOGCOLOUR)
stream = logging.StreamHandler()
stream.setFormatter(formatter)
logger.addHandler(stream)
logger.setLevel((logging.ERROR - (verbosity * 10)))
return logger
def sheen_walk(basedir, subs, base_clean,logger,reverse):
for dirpath,dirnames, filenames in os.walk(basedir):
for file in filenames:
newpath = base_clean+"/"+string_replace(dirpath,subs,reverse)
if not os.path.exists(newpath):
os.makedirs(newpath)
cleanpath = os.path.join(newpath, string_replace(file,subs,reverse))
inputpath = os.path.join(dirpath, file)
# do the replacement line-by-line
with open(inputpath) as infile, open(cleanpath, 'w') as outfile:
logger.debug("Processing file %s" % infile.name)
line_number = 0
process_cert = False
for line in infile:
line_number += 1
# check if this is the start of a certificate
if "BEGIN" in line:
if "END" in line:
continue
else:
outfile.write(line)
process_cert = True
continue
elif process_cert:
if "END" not in line:
continue
else:
outfile.write(line)
process_cert = False
else:
try:
outfile.write(string_replace(line,subs,reverse))
except UnicodeDecodeError:
logger.error("Error processing line %d in file %s" % (line_number,infile.name))
logger.debug("Cleaned file written to %s" % outfile.name)
infile.close()
outfile.close()
def cleanup_git(basedir):
for dirpath, dirnames, filenames in os.walk(basedir):
if ".git" in dirpath:
shutil.rmtree(dirpath)
def string_replace(input,subs,reverse):
with open(subs) as json_file:
json_data = json.load(json_file)
for k,v in six.iteritems(json_data):
if(reverse):
input = input.replace(v,k)
else:
input = input.replace(k,v)
return input
def main():
parser = argparse.ArgumentParser(description='Replace occurrences of specific patterns in files and folders')
parser.add_argument('--dir', dest='basedir', help='Base export directory')
parser.add_argument('--json-replace', dest='subs', help='JSON file with key-value pairs of replacements to make')
parser.add_argument('--reverse',dest='reverse', action="store_true", help='Reverse the order of the substitutions')
parser.add_argument("-v", "--verbose", action="count", dest="verbosity",
help="Verbose mode. Can be used multiple times to increase output. Use -vvv for debugging output.")
args = parser.parse_args()
# Setup logging
verbosity = args.verbosity
if args.verbosity == None or args.verbosity < 0:
verbosity = 0
logger = _setup_logging(verbosity)
if not args.basedir:
logger.error("Base directory not specified")
parser.print_help()
sys.exit(1)
elif not args.subs:
logger.error("JSON substitutions file not specified")
parser.print_help()
sys.exit(1)
# Create the cleaned directory structure, replacing dirnames with substitutions
base_clean = args.basedir + "_mrsheen_" + datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
logger.info("Base cleaned directory is " + base_clean)
# cleanup any git subdirectories
logger.info("Starting git deletion")
cleanup_git(basedir=args.basedir)
logger.info("Starting directory walk")
sheen_walk(basedir=args.basedir, subs=args.subs, base_clean=base_clean,logger=logger, reverse=args.reverse)
if __name__ == "__main__":
main()
|
"""
Copyright 2010 IO Rodeo Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import division
import roslib
roslib.load_manifest('water_channel_mechanics')
import rospy
import math
import copy
import cad.csg_objects as csg
import cad.finite_solid_objects as fso
import cad.pattern_objects as po
import cad_library.origin as origin
import cad.export.bom as bom
import airbearing
AIRBEARING_MOUNT_PLATE_PARAMETERS = {
'bearing_type': 'RAB6',
'slide_travel': 4,
'color': [0.7,0.7,0.7,1.0],
'z': 0.5,
'hole_diameter': 0.26,
'show_origin': False,
}
def get_parameters():
return copy.deepcopy(AIRBEARING_MOUNT_PLATE_PARAMETERS)
class AirbearingMountPlate(csg.Difference):
def __init__(self):
super(AirbearingMountPlate, self).__init__()
self.parameters = AIRBEARING_MOUNT_PLATE_PARAMETERS
ab = airbearing.RAB(bearing_type=self.parameters['bearing_type'],slide_travel=self.parameters['slide_travel'])
self.ab_parameters = ab.get_parameters()
self.__make_airbearing_mount_plate()
self.__make_holes()
self.__set_bom()
self.__make_origin()
self.set_color(self.parameters['color'],recursive=True)
def get_parameters(self):
return copy.deepcopy(self.parameters)
def __make_airbearing_mount_plate(self):
x = self.ab_parameters['carriage_length']
self.parameters['x'] = x
y = self.ab_parameters['carriage_width']
self.parameters['y'] = y
z = self.parameters['z']
abmp = fso.Box(x=x,y=y,z=z)
self.add_obj(abmp)
def __make_holes(self):
# Add airbearing mount holes
hole_diameter = self.parameters['hole_diameter']
hole = fso.Cylinder(r=hole_diameter/2,l=self.parameters['z']*2)
h_x = self.ab_parameters['carriage_screw_dL']/2
h_y = self.ab_parameters['carriage_screw_dW']/2
holes = po.LinearArray(hole,x=[-h_x,h_x],y=[-h_y,h_y],z=0)
self.add_obj(holes)
# Add y_beam mount counterbore holes
cb_diameter = 7/16
cb_depth = 0.25
cb = fso.Cylinder(r=cb_diameter/2,l=self.parameters['z'])
cb.translate([0,0,(-self.parameters['z'] + cb_depth)])
cbh = cb | hole
cbhs = po.LinearArray(cbh,x=[-2.5,0,2.5],y=[-1.5,1.5],z=0)
self.add_obj(cbhs)
def __set_bom(self):
scale = self.get_scale()
BOM = bom.BOMObject()
BOM.set_parameter('name','airbearing_mount_plate')
BOM.set_parameter('description','Mounts air bearing carriage to t_slotted beam')
BOM.set_parameter('dimensions','x: {x:0.3f}, y: {y:0.3f}, z: {z:0.3f}'.format(x=self.parameters['x']*scale[0],y=self.parameters['y']*scale[1],z=self.parameters['z']*scale[2]))
BOM.set_parameter('vendor','?')
BOM.set_parameter('part number','?')
self.set_object_parameter('bom',BOM)
def __make_origin(self):
o = origin.Origin(mag=10)
if self.parameters['show_origin']:
self.add_obj(o)
if __name__ == "__main__":
airbearing_mount_plate = AirbearingMountPlate()
airbearing_mount_plate.set_object_parameter('slice',True)
airbearing_mount_plate.export()
|
<filename>TD3.py
import gym
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import collections
import random
import numpy as np
import copy
class ReplayBuffer():
def __init__(self):
self.buffer = collections.deque(maxlen=buffer_limit)
def put(self, transition):
self.buffer.append(transition)
def sample(self, n):
mini_batch = random.sample(self.buffer, n)
s_lst, a_lst, r_lst, s_prime_lst, done_mask_lst = [], [], [], [], []
for transition in mini_batch:
s, a, r, s_prime, done_mask = transition
s_lst.append(s)
a_lst.append([a])
r_lst.append([r])
s_prime_lst.append(s_prime)
done_mask_lst.append([done_mask])
return torch.tensor(s_lst, dtype=torch.float), torch.tensor(a_lst, dtype=torch.float), \
torch.tensor(r_lst, dtype=torch.float), torch.tensor(s_prime_lst, dtype=torch.float), \
torch.tensor(done_mask_lst, dtype=torch.float)
def size(self):
return len(self.buffer)
class NoiseGenerator:
def __init__(self, mu, sigma):
self.mu = mu
self.sigma = sigma
def generate(self):
return np.random.normal(self.mu, self.sigma, 1)[0]
class MuNet(nn.Module):
def __init__(self):
super(MuNet, self).__init__()
self.fc1 = nn.Linear(3, 128)
self.fc2 = nn.Linear(128, 64)
self.fc_mu = nn.Linear(64, 1)
def forward(self, x):
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
mu = torch.tanh(self.fc_mu(x)) * 2
return mu
class QNet(nn.Module):
def __init__(self):
super(QNet, self).__init__()
self.fc_s = nn.Linear(3, 64)
self.fc_a = nn.Linear(1, 64)
self.fc_q = nn.Linear(128, 32)
self.fc_3 = nn.Linear(32, 1)
def forward(self, x, a):
h1 = F.relu(self.fc_s(x))
h2 = F.relu(self.fc_a(a))
cat = torch.cat([h1, h2], dim=1)
q = F.relu(self.fc_q(cat))
q = self.fc_3(q)
return q
class TD3(nn.Module):
def __init__(self):
super(TD3, self).__init__()
self.q_net_1 = QNet()
self.q_net_2 = QNet()
self.q_net_optimizer = optim.Adam(list(self.q_net_1.parameters()) \
+ list(self.q_net_2.parameters()), lr=critic_learning_rate)
self.mu_net = MuNet()
self.mu_net_optimizer = optim.Adam(self.mu_net.parameters(), lr=actor_learning_rate)
self.target_q_net_1 = copy.deepcopy(self.q_net_1)
self.target_q_net_2 = copy.deepcopy(self.q_net_2)
self.target_mu_net = copy.deepcopy(self.mu_net)
self.noise_generator = NoiseGenerator(0, 0.2)
self.train_num = 1
self.d = 2
def pi(self, x):
x = self.mu_net(x)
return x
def train_net(self):
s, a, r, s_prime, done_mask = memory.sample(batch_size)
tilde_a = self.target_mu_net(s_prime) + torch.tensor(np.clip(self.noise_generator.generate(), -0.5, 0.5))
tilde_a = torch.clamp(tilde_a, -2, 2).detach()
y = r + discount_factor * torch.min(self.target_q_net_1(s_prime, tilde_a),
self.target_q_net_2(s_prime, tilde_a))
q_loss = F.mse_loss(y.detach(), self.q_net_1(s, a)) + F.mse_loss(y.detach(), self.q_net_2(s, a))
self.q_net_optimizer.zero_grad()
q_loss.backward()
self.q_net_optimizer.step()
if self.train_num % self.d == 0:
mu_loss = - self.q_net_1(s, self.mu_net(s)).mean()
self.mu_net_optimizer.zero_grad()
mu_loss.backward()
self.mu_net_optimizer.step()
for param, target_param in zip(self.q_net_1.parameters(), self.target_q_net_1.parameters()):
target_param.data.copy_(tau * param.data + (1 - tau) * target_param.data)
for param, target_param in zip(self.q_net_2.parameters(), self.target_q_net_2.parameters()):
target_param.data.copy_(tau * param.data + (1 - tau) * target_param.data)
for param, target_param in zip(self.mu_net.parameters(), self.target_mu_net.parameters()):
target_param.data.copy_(tau * param.data + (1 - tau) * target_param.data)
self.train_num += 1
buffer_limit = 50000
actor_learning_rate = 0.001
critic_learning_rate = 0.001
batch_size = 100
discount_factor = 0.99
tau = 0.005
env = gym.make('Pendulum-v0')
model = TD3()
memory = ReplayBuffer()
print_interval = 20
def main(render=False):
score = 0.0
pi_noise_generator = NoiseGenerator(0, 0.1)
for n_epi in range(10000):
s = env.reset()
global_step = 0
done = False
r = 0
while not done:
global_step += 1
if render:
env.render()
a = model.pi(torch.from_numpy(s).float()).item()
a = a + pi_noise_generator.generate()
a = max(min(a, 2), -2)
s_prime, r, done, info = env.step([a])
memory.put((s, a, r / 100.0, s_prime, done))
s = s_prime
# print('global_step : ',global_step, ' action : ',a,' reward : ',r,' done : ',done)
score += r
if done:
break
if memory.size() > 2000:
model.train_net()
if n_epi % print_interval == 0 and n_epi != 0:
print("# of episode :{}, avg score : {:.1f}".format(n_epi, score / print_interval))
score = 0.0
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from unittest import TestCase
try:
import numpy as np
from scipy.sparse import csr_matrix
except ImportError:
pass
from jubakit.classifier import Schema, Dataset, Classifier, Config
from jubakit.compat import *
from . import requireSklearn, requireEmbedded
from .stub import *
class SchemaTest(TestCase):
def test_simple(self):
schema = Schema({
'k1': Schema.STRING,
'k2': Schema.LABEL,
})
(label, d) = schema.transform({'k1': 'abc', 'k2': 'def'})
self.assertEqual(label, 'def')
self.assertEqual({'k1': 'abc'}, dict(d.string_values))
(label, d) = schema.transform({'k1': 'foo', 'k2': None}) # unlabeled data
self.assertEqual(label, None)
self.assertEqual({'k1': 'foo'}, dict(d.string_values))
def test_without_label(self):
# schema without label can be defined
Schema({
'k1': Schema.STRING,
})
def test_illegal_label(self):
# schema with multiple labels
self.assertRaises(RuntimeError, Schema, {
'k1': Schema.LABEL,
'k2': Schema.LABEL
})
# schema fallback set to label
self.assertRaises(RuntimeError, Schema, {
'k1': Schema.LABEL
}, Schema.LABEL)
class DatasetTest(TestCase):
def test_simple(self):
loader = StubLoader()
schema = Schema({'v': Schema.LABEL})
ds = Dataset(loader, schema)
for (idx, (label, d)) in ds:
self.assertEqual(unicode_t(idx+1), label)
self.assertEqual(0, len(d.string_values))
self.assertEqual(0, len(d.num_values))
self.assertEqual(0, len(d.binary_values))
self.assertEqual(['1','2','3'], list(ds.get_labels()))
def test_predict(self):
loader = StubLoader()
dataset = Dataset(loader) # predict
self.assertEqual(['v', 1.0], dataset[0][1].num_values[0])
def test_get_labels(self):
loader = StubLoader()
schema = Schema({'v': Schema.LABEL})
ds = Dataset(loader, schema)
self.assertEqual(['1', '2', '3'], list(ds.get_labels()))
def test_invalid_get_labels(self):
loader = StubLoader()
schema = Schema({'v': Schema.LABEL})
ds = Dataset(loader, schema, static=False)
# get_labels returns generator; as generator will be evaluated
# when actually iterating over it, pass it to list().
self.assertRaises(RuntimeError, list, ds.get_labels())
@requireSklearn
def test_from_data(self):
# load from array format
ds = Dataset.from_data(
[ [10,20,30], [20,10,50], [40,10,30] ], # data
[ 0, 1, 0 ], # labels
['k1', 'k2', 'k3'], # feature_names
['pos', 'neg'], # label_names
)
expected_labels = ['pos', 'neg', 'pos']
expected_k1s = [10, 20, 40]
actual_labels = []
actual_k1s = []
for (idx, (label, d)) in ds:
actual_labels.append(label)
actual_k1s.append(dict(d.num_values)['k1'])
self.assertEqual(expected_labels, actual_labels)
self.assertEqual(expected_k1s, actual_k1s)
# load from scipy.sparse format
ds = Dataset.from_data(
self._create_matrix(), # data
[ 0, 1, 0 ], # labels
[ 'k1', 'k2', 'k3'], # feature_names
[ 'pos', 'neg'], # label_names
)
expected_labels = ['pos', 'neg', 'pos']
expected_k1s = [1, None, 4]
expected_k3s = [2, 3, 6]
actual_labels = []
actual_k1s = []
actual_k3s = []
for (idx, (label, d)) in ds:
actual_labels.append(label)
actual_k1s.append(dict(d.num_values).get('k1', None))
actual_k3s.append(dict(d.num_values).get('k3', None))
self.assertEqual(expected_labels, actual_labels)
self.assertEqual(expected_k1s, actual_k1s)
self.assertEqual(expected_k3s, actual_k3s)
def test_from_array(self):
ds = Dataset.from_array(
[ [10,20,30], [20,10,50], [40,10,30] ], # data
[ 0, 1, 0 ], # labels
['k1', 'k2', 'k3'], # feature_names
['pos', 'neg'], # label_names
)
expected_labels = ['pos', 'neg', 'pos']
expected_k1s = [10, 20, 40]
actual_labels = []
actual_k1s = []
for (idx, (label, d)) in ds:
actual_labels.append(label)
actual_k1s.append(dict(d.num_values)['k1'])
self.assertEqual(expected_labels, actual_labels)
self.assertEqual(expected_k1s, actual_k1s)
def test_from_array_without_label(self):
ds = Dataset.from_array(
[ [10,20,30], [20,10,50], [40,10,30] ], # data
None, # labels
['k1', 'k2', 'k3'], # feature_names
['pos', 'neg'], # label_names
)
expected_labels = [None, None, None]
expected_k1s = [10, 20, 40]
actual_labels = []
actual_k1s = []
for (idx, (label, d)) in ds:
actual_labels.append(label)
actual_k1s.append(dict(d.num_values)['k1'])
self.assertEqual(expected_labels, actual_labels)
self.assertEqual(expected_k1s, actual_k1s)
@requireSklearn
def test_from_matrix(self):
ds = Dataset.from_matrix(
self._create_matrix(), # data
[ 0, 1, 0 ], # labels
[ 'k1', 'k2', 'k3'], # feature_names
[ 'pos', 'neg'], # label_names
)
expected_labels = ['pos', 'neg', 'pos']
expected_k1s = [1,None,4]
expected_k3s = [2,3,6]
actual_labels = []
actual_k1s = []
actual_k3s = []
for (idx, (label, d)) in ds:
actual_labels.append(label)
actual_k1s.append(dict(d.num_values).get('k1', None))
actual_k3s.append(dict(d.num_values).get('k3', None))
self.assertEqual(expected_labels, actual_labels)
self.assertEqual(expected_k1s, actual_k1s)
self.assertEqual(expected_k3s, actual_k3s)
def _create_matrix(self):
"""
Create a sparse matrix:
[[1, 0, 2],
[0, 0, 3],
[4, 5, 6]]
"""
row = np.array([0, 0, 1, 2, 2, 2])
col = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1, 2, 3, 4, 5, 6])
return csr_matrix((data, (row, col)), shape=(3, 3))
class ClassifierTest(TestCase):
def test_simple(self):
classifier = Classifier()
@requireEmbedded
def test_embedded(self):
classifier = Classifier.run(Config(), embedded=True)
class ConfigTest(TestCase):
def test_simple(self):
config = Config()
self.assertEqual('AROW', config['method'])
def test_methods(self):
config = Config()
self.assertTrue(isinstance(config.methods(), list))
def test_default(self):
config = Config.default()
self.assertEqual('AROW', config['method'])
def test_method_param(self):
self.assertTrue('parameter' not in Config(method='PA'))
self.assertTrue('regularization_weight' in Config(method='PA1')['parameter'])
self.assertTrue('nearest_neighbor_num' in Config(method='NN')['parameter'])
self.assertTrue('nearest_neighbor_num' in Config(method='cosine')['parameter'])
self.assertTrue('nearest_neighbor_num' in Config(method='euclidean')['parameter'])
def test_invalid_method(self):
self.assertRaises(RuntimeError, Config._default_parameter, 'invalid_method')
|
<filename>src/metanetx_post/cli/reaction/expasy.py
# Copyright (c) 2020, <NAME>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Define the CLI for enriching ExPASy reaction information."""
import json
import logging
from pathlib import Path
import click
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from ...api.reaction import expasy as expasy_api
from ..helpers import JSON_SEPARATORS, convert2json_type
logger = logging.getLogger(__name__)
Session = sessionmaker()
@click.group()
@click.help_option("--help", "-h")
def expasy():
"""Subcommands for processing ExPASy information."""
pass
@expasy.command()
@click.help_option("--help", "-h")
@click.argument("email", metavar="<EMAIL>")
@click.option(
"--filename",
"-f",
type=click.Path(dir_okay=False, writable=True),
default="enzyme.rdf",
show_default=True,
help="The output path for the ExPASy RDF file.",
)
def extract(email: str, filename: click.Path):
"""
Fetch the ExPASy enzyme descriptions.
\b
EMAIL is required and is used to identify yourself to the ExPASy FTP server.
"""
logger.info("Downloading enzyme descriptions from ExPASy.")
# Unless we are debugging, we make the aioftp logger less noisy.
if logger.getEffectiveLevel() > logging.DEBUG:
logging.getLogger("aioftp").setLevel(logging.WARNING)
expasy_api.extract(email, Path(filename))
@expasy.command()
@click.help_option("--help", "-h")
@click.argument("rdf", metavar="<RDF>", type=click.Path(dir_okay=False, exists=True))
@click.option(
"--filename",
"-f",
type=click.Path(dir_okay=False, writable=True),
default="expasy_reaction_names.json",
show_default=True,
help="The output path for the ExPASy reaction identifier to name JSON file.",
)
@click.option(
"--replacement",
type=click.Path(dir_okay=False, writable=True),
default="expasy_replacements.json",
show_default=True,
help="The output path for the EC-code replacement JSON file.",
)
def transform(rdf: click.Path, filename: click.Path, replacement: click.Path):
"""
Generate a mapping of EC-codes to names and obsolete EC-codes.
\b
RDF The path on the local filesystem from where to load the RDF graph.
"""
logger.info("Generating EC-code to name mapping and obsolete codes.")
id2names, obsoletes = expasy_api.transform(Path(rdf))
with Path(filename).open("w") as handle:
json.dump(
id2names, handle, default=convert2json_type, separators=JSON_SEPARATORS
)
with Path(replacement).open("w") as handle:
json.dump(obsoletes, handle, separators=JSON_SEPARATORS)
@expasy.command()
@click.help_option("--help", "-h")
@click.argument("db-uri", metavar="<URI>")
@click.argument(
"filename", metavar="<FILENAME>", type=click.Path(dir_okay=False, exists=True)
)
@click.argument(
"replacement", metavar="<REPLACEMENT>", type=click.Path(dir_okay=False, exists=True)
)
def load(db_uri: str, filename: click.Path, replacement: click.Path):
"""
Load EC-code names into a database.
\b
URI is a string interpreted as an rfc1738 compatible database URI.
FILENAME is the EC-code to name mapping JSON file.
REPLACEMENT is the EC-code replacment JSON file.
"""
engine = create_engine(db_uri)
session = Session(bind=engine)
with Path(filename).open() as handle:
id2name = json.load(handle)
with Path(replacement).open() as handle:
obsoletes = json.load(handle)
logger.info("Adding EC-code names to database.")
try:
expasy_api.load(session, id2name, obsoletes)
finally:
session.close()
|
# coding=utf-8
# *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***
import warnings
import pulumi
import pulumi.runtime
from typing import Any, Mapping, Optional, Sequence, Union, overload
from .. import _utilities
__all__ = ['NatGatewayArgs', 'NatGateway']
@pulumi.input_type
class NatGatewayArgs:
def __init__(__self__, *,
resource_group_name: pulumi.Input[str],
idle_timeout_in_minutes: Optional[pulumi.Input[int]] = None,
location: Optional[pulumi.Input[str]] = None,
name: Optional[pulumi.Input[str]] = None,
public_ip_address_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
public_ip_prefix_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
sku_name: Optional[pulumi.Input[str]] = None,
tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
zones: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None):
"""
The set of arguments for constructing a NatGateway resource.
:param pulumi.Input[str] resource_group_name: Specifies the name of the Resource Group in which the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[int] idle_timeout_in_minutes: The idle timeout which should be used in minutes. Defaults to `4`.
:param pulumi.Input[str] location: Specifies the supported Azure location where the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[str] name: Specifies the name of the NAT Gateway. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_address_ids: A list of Public IP Address ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_prefix_ids: / **Deprecated in favour of `network.NatGatewayPublicIpPrefixAssociation`**) A list of Public IP Prefix ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[str] sku_name: The SKU which should be used. At this time the only supported value is `Standard`. Defaults to `Standard`.
:param pulumi.Input[Mapping[str, pulumi.Input[str]]] tags: A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] zones: A list of availability zones where the NAT Gateway should be provisioned. Changing this forces a new resource to be created.
"""
pulumi.set(__self__, "resource_group_name", resource_group_name)
if idle_timeout_in_minutes is not None:
pulumi.set(__self__, "idle_timeout_in_minutes", idle_timeout_in_minutes)
if location is not None:
pulumi.set(__self__, "location", location)
if name is not None:
pulumi.set(__self__, "name", name)
if public_ip_address_ids is not None:
warnings.warn("""Inline Public IP Address ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""", DeprecationWarning)
pulumi.log.warn("""public_ip_address_ids is deprecated: Inline Public IP Address ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""")
if public_ip_address_ids is not None:
pulumi.set(__self__, "public_ip_address_ids", public_ip_address_ids)
if public_ip_prefix_ids is not None:
warnings.warn("""Inline Public IP Prefix ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_prefix_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""", DeprecationWarning)
pulumi.log.warn("""public_ip_prefix_ids is deprecated: Inline Public IP Prefix ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_prefix_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""")
if public_ip_prefix_ids is not None:
pulumi.set(__self__, "public_ip_prefix_ids", public_ip_prefix_ids)
if sku_name is not None:
pulumi.set(__self__, "sku_name", sku_name)
if tags is not None:
pulumi.set(__self__, "tags", tags)
if zones is not None:
pulumi.set(__self__, "zones", zones)
@property
@pulumi.getter(name="resourceGroupName")
def resource_group_name(self) -> pulumi.Input[str]:
"""
Specifies the name of the Resource Group in which the NAT Gateway should exist. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "resource_group_name")
@resource_group_name.setter
def resource_group_name(self, value: pulumi.Input[str]):
pulumi.set(self, "resource_group_name", value)
@property
@pulumi.getter(name="idleTimeoutInMinutes")
def idle_timeout_in_minutes(self) -> Optional[pulumi.Input[int]]:
"""
The idle timeout which should be used in minutes. Defaults to `4`.
"""
return pulumi.get(self, "idle_timeout_in_minutes")
@idle_timeout_in_minutes.setter
def idle_timeout_in_minutes(self, value: Optional[pulumi.Input[int]]):
pulumi.set(self, "idle_timeout_in_minutes", value)
@property
@pulumi.getter
def location(self) -> Optional[pulumi.Input[str]]:
"""
Specifies the supported Azure location where the NAT Gateway should exist. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "location")
@location.setter
def location(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "location", value)
@property
@pulumi.getter
def name(self) -> Optional[pulumi.Input[str]]:
"""
Specifies the name of the NAT Gateway. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "name")
@name.setter
def name(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "name", value)
@property
@pulumi.getter(name="publicIpAddressIds")
def public_ip_address_ids(self) -> Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]:
"""
A list of Public IP Address ID's which should be associated with the NAT Gateway resource.
"""
return pulumi.get(self, "public_ip_address_ids")
@public_ip_address_ids.setter
def public_ip_address_ids(self, value: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]):
pulumi.set(self, "public_ip_address_ids", value)
@property
@pulumi.getter(name="publicIpPrefixIds")
def public_ip_prefix_ids(self) -> Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]:
"""
/ **Deprecated in favour of `network.NatGatewayPublicIpPrefixAssociation`**) A list of Public IP Prefix ID's which should be associated with the NAT Gateway resource.
"""
return pulumi.get(self, "public_ip_prefix_ids")
@public_ip_prefix_ids.setter
def public_ip_prefix_ids(self, value: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]):
pulumi.set(self, "public_ip_prefix_ids", value)
@property
@pulumi.getter(name="skuName")
def sku_name(self) -> Optional[pulumi.Input[str]]:
"""
The SKU which should be used. At this time the only supported value is `Standard`. Defaults to `Standard`.
"""
return pulumi.get(self, "sku_name")
@sku_name.setter
def sku_name(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "sku_name", value)
@property
@pulumi.getter
def tags(self) -> Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]]:
"""
A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "tags")
@tags.setter
def tags(self, value: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]]):
pulumi.set(self, "tags", value)
@property
@pulumi.getter
def zones(self) -> Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]:
"""
A list of availability zones where the NAT Gateway should be provisioned. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "zones")
@zones.setter
def zones(self, value: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]):
pulumi.set(self, "zones", value)
@pulumi.input_type
class _NatGatewayState:
def __init__(__self__, *,
idle_timeout_in_minutes: Optional[pulumi.Input[int]] = None,
location: Optional[pulumi.Input[str]] = None,
name: Optional[pulumi.Input[str]] = None,
public_ip_address_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
public_ip_prefix_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
resource_group_name: Optional[pulumi.Input[str]] = None,
resource_guid: Optional[pulumi.Input[str]] = None,
sku_name: Optional[pulumi.Input[str]] = None,
tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
zones: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None):
"""
Input properties used for looking up and filtering NatGateway resources.
:param pulumi.Input[int] idle_timeout_in_minutes: The idle timeout which should be used in minutes. Defaults to `4`.
:param pulumi.Input[str] location: Specifies the supported Azure location where the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[str] name: Specifies the name of the NAT Gateway. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_address_ids: A list of Public IP Address ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_prefix_ids: / **Deprecated in favour of `network.NatGatewayPublicIpPrefixAssociation`**) A list of Public IP Prefix ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[str] resource_group_name: Specifies the name of the Resource Group in which the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[str] resource_guid: The resource GUID property of the NAT Gateway.
:param pulumi.Input[str] sku_name: The SKU which should be used. At this time the only supported value is `Standard`. Defaults to `Standard`.
:param pulumi.Input[Mapping[str, pulumi.Input[str]]] tags: A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] zones: A list of availability zones where the NAT Gateway should be provisioned. Changing this forces a new resource to be created.
"""
if idle_timeout_in_minutes is not None:
pulumi.set(__self__, "idle_timeout_in_minutes", idle_timeout_in_minutes)
if location is not None:
pulumi.set(__self__, "location", location)
if name is not None:
pulumi.set(__self__, "name", name)
if public_ip_address_ids is not None:
warnings.warn("""Inline Public IP Address ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""", DeprecationWarning)
pulumi.log.warn("""public_ip_address_ids is deprecated: Inline Public IP Address ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""")
if public_ip_address_ids is not None:
pulumi.set(__self__, "public_ip_address_ids", public_ip_address_ids)
if public_ip_prefix_ids is not None:
warnings.warn("""Inline Public IP Prefix ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_prefix_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""", DeprecationWarning)
pulumi.log.warn("""public_ip_prefix_ids is deprecated: Inline Public IP Prefix ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_prefix_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""")
if public_ip_prefix_ids is not None:
pulumi.set(__self__, "public_ip_prefix_ids", public_ip_prefix_ids)
if resource_group_name is not None:
pulumi.set(__self__, "resource_group_name", resource_group_name)
if resource_guid is not None:
pulumi.set(__self__, "resource_guid", resource_guid)
if sku_name is not None:
pulumi.set(__self__, "sku_name", sku_name)
if tags is not None:
pulumi.set(__self__, "tags", tags)
if zones is not None:
pulumi.set(__self__, "zones", zones)
@property
@pulumi.getter(name="idleTimeoutInMinutes")
def idle_timeout_in_minutes(self) -> Optional[pulumi.Input[int]]:
"""
The idle timeout which should be used in minutes. Defaults to `4`.
"""
return pulumi.get(self, "idle_timeout_in_minutes")
@idle_timeout_in_minutes.setter
def idle_timeout_in_minutes(self, value: Optional[pulumi.Input[int]]):
pulumi.set(self, "idle_timeout_in_minutes", value)
@property
@pulumi.getter
def location(self) -> Optional[pulumi.Input[str]]:
"""
Specifies the supported Azure location where the NAT Gateway should exist. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "location")
@location.setter
def location(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "location", value)
@property
@pulumi.getter
def name(self) -> Optional[pulumi.Input[str]]:
"""
Specifies the name of the NAT Gateway. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "name")
@name.setter
def name(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "name", value)
@property
@pulumi.getter(name="publicIpAddressIds")
def public_ip_address_ids(self) -> Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]:
"""
A list of Public IP Address ID's which should be associated with the NAT Gateway resource.
"""
return pulumi.get(self, "public_ip_address_ids")
@public_ip_address_ids.setter
def public_ip_address_ids(self, value: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]):
pulumi.set(self, "public_ip_address_ids", value)
@property
@pulumi.getter(name="publicIpPrefixIds")
def public_ip_prefix_ids(self) -> Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]:
"""
/ **Deprecated in favour of `network.NatGatewayPublicIpPrefixAssociation`**) A list of Public IP Prefix ID's which should be associated with the NAT Gateway resource.
"""
return pulumi.get(self, "public_ip_prefix_ids")
@public_ip_prefix_ids.setter
def public_ip_prefix_ids(self, value: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]):
pulumi.set(self, "public_ip_prefix_ids", value)
@property
@pulumi.getter(name="resourceGroupName")
def resource_group_name(self) -> Optional[pulumi.Input[str]]:
"""
Specifies the name of the Resource Group in which the NAT Gateway should exist. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "resource_group_name")
@resource_group_name.setter
def resource_group_name(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "resource_group_name", value)
@property
@pulumi.getter(name="resourceGuid")
def resource_guid(self) -> Optional[pulumi.Input[str]]:
"""
The resource GUID property of the NAT Gateway.
"""
return pulumi.get(self, "resource_guid")
@resource_guid.setter
def resource_guid(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "resource_guid", value)
@property
@pulumi.getter(name="skuName")
def sku_name(self) -> Optional[pulumi.Input[str]]:
"""
The SKU which should be used. At this time the only supported value is `Standard`. Defaults to `Standard`.
"""
return pulumi.get(self, "sku_name")
@sku_name.setter
def sku_name(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "sku_name", value)
@property
@pulumi.getter
def tags(self) -> Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]]:
"""
A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "tags")
@tags.setter
def tags(self, value: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]]):
pulumi.set(self, "tags", value)
@property
@pulumi.getter
def zones(self) -> Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]:
"""
A list of availability zones where the NAT Gateway should be provisioned. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "zones")
@zones.setter
def zones(self, value: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]]):
pulumi.set(self, "zones", value)
class NatGateway(pulumi.CustomResource):
@overload
def __init__(__self__,
resource_name: str,
opts: Optional[pulumi.ResourceOptions] = None,
idle_timeout_in_minutes: Optional[pulumi.Input[int]] = None,
location: Optional[pulumi.Input[str]] = None,
name: Optional[pulumi.Input[str]] = None,
public_ip_address_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
public_ip_prefix_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
resource_group_name: Optional[pulumi.Input[str]] = None,
sku_name: Optional[pulumi.Input[str]] = None,
tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
zones: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
__props__=None):
"""
Manages a Azure NAT Gateway.
## Example Usage
```python
import pulumi
import pulumi_azure as azure
example_resource_group = azure.core.ResourceGroup("exampleResourceGroup", location="West Europe")
example_public_ip = azure.network.PublicIp("examplePublicIp",
location=example_resource_group.location,
resource_group_name=example_resource_group.name,
allocation_method="Static",
sku="Standard",
zones=["1"])
example_public_ip_prefix = azure.network.PublicIpPrefix("examplePublicIpPrefix",
location=example_resource_group.location,
resource_group_name=example_resource_group.name,
prefix_length=30,
zones=["1"])
example_nat_gateway = azure.network.NatGateway("exampleNatGateway",
location=example_resource_group.location,
resource_group_name=example_resource_group.name,
public_ip_address_ids=[example_public_ip.id],
public_ip_prefix_ids=[example_public_ip_prefix.id],
sku_name="Standard",
idle_timeout_in_minutes=10,
zones=["1"])
```
## Import
NAT Gateway can be imported using the `resource id`, e.g.
```sh
$ pulumi import azure:network/natGateway:NatGateway test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/natGateways/gateway1
```
:param str resource_name: The name of the resource.
:param pulumi.ResourceOptions opts: Options for the resource.
:param pulumi.Input[int] idle_timeout_in_minutes: The idle timeout which should be used in minutes. Defaults to `4`.
:param pulumi.Input[str] location: Specifies the supported Azure location where the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[str] name: Specifies the name of the NAT Gateway. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_address_ids: A list of Public IP Address ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_prefix_ids: / **Deprecated in favour of `network.NatGatewayPublicIpPrefixAssociation`**) A list of Public IP Prefix ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[str] resource_group_name: Specifies the name of the Resource Group in which the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[str] sku_name: The SKU which should be used. At this time the only supported value is `Standard`. Defaults to `Standard`.
:param pulumi.Input[Mapping[str, pulumi.Input[str]]] tags: A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] zones: A list of availability zones where the NAT Gateway should be provisioned. Changing this forces a new resource to be created.
"""
...
@overload
def __init__(__self__,
resource_name: str,
args: NatGatewayArgs,
opts: Optional[pulumi.ResourceOptions] = None):
"""
Manages a Azure NAT Gateway.
## Example Usage
```python
import pulumi
import pulumi_azure as azure
example_resource_group = azure.core.ResourceGroup("exampleResourceGroup", location="West Europe")
example_public_ip = azure.network.PublicIp("examplePublicIp",
location=example_resource_group.location,
resource_group_name=example_resource_group.name,
allocation_method="Static",
sku="Standard",
zones=["1"])
example_public_ip_prefix = azure.network.PublicIpPrefix("examplePublicIpPrefix",
location=example_resource_group.location,
resource_group_name=example_resource_group.name,
prefix_length=30,
zones=["1"])
example_nat_gateway = azure.network.NatGateway("exampleNatGateway",
location=example_resource_group.location,
resource_group_name=example_resource_group.name,
public_ip_address_ids=[example_public_ip.id],
public_ip_prefix_ids=[example_public_ip_prefix.id],
sku_name="Standard",
idle_timeout_in_minutes=10,
zones=["1"])
```
## Import
NAT Gateway can be imported using the `resource id`, e.g.
```sh
$ pulumi import azure:network/natGateway:NatGateway test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/natGateways/gateway1
```
:param str resource_name: The name of the resource.
:param NatGatewayArgs args: The arguments to use to populate this resource's properties.
:param pulumi.ResourceOptions opts: Options for the resource.
"""
...
def __init__(__self__, resource_name: str, *args, **kwargs):
resource_args, opts = _utilities.get_resource_args_opts(NatGatewayArgs, pulumi.ResourceOptions, *args, **kwargs)
if resource_args is not None:
__self__._internal_init(resource_name, opts, **resource_args.__dict__)
else:
__self__._internal_init(resource_name, *args, **kwargs)
def _internal_init(__self__,
resource_name: str,
opts: Optional[pulumi.ResourceOptions] = None,
idle_timeout_in_minutes: Optional[pulumi.Input[int]] = None,
location: Optional[pulumi.Input[str]] = None,
name: Optional[pulumi.Input[str]] = None,
public_ip_address_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
public_ip_prefix_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
resource_group_name: Optional[pulumi.Input[str]] = None,
sku_name: Optional[pulumi.Input[str]] = None,
tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
zones: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
__props__=None):
if opts is None:
opts = pulumi.ResourceOptions()
if not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')
if opts.version is None:
opts.version = _utilities.get_version()
if opts.id is None:
if __props__ is not None:
raise TypeError('__props__ is only valid when passed in combination with a valid opts.id to get an existing resource')
__props__ = NatGatewayArgs.__new__(NatGatewayArgs)
__props__.__dict__["idle_timeout_in_minutes"] = idle_timeout_in_minutes
__props__.__dict__["location"] = location
__props__.__dict__["name"] = name
if public_ip_address_ids is not None and not opts.urn:
warnings.warn("""Inline Public IP Address ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""", DeprecationWarning)
pulumi.log.warn("""public_ip_address_ids is deprecated: Inline Public IP Address ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""")
__props__.__dict__["public_ip_address_ids"] = public_ip_address_ids
if public_ip_prefix_ids is not None and not opts.urn:
warnings.warn("""Inline Public IP Prefix ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_prefix_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""", DeprecationWarning)
pulumi.log.warn("""public_ip_prefix_ids is deprecated: Inline Public IP Prefix ID Associations have been deprecated in favour of the `azurerm_nat_gateway_public_ip_prefix_association` pluginsdk. This field will be removed in the next major version of the Azure Provider.""")
__props__.__dict__["public_ip_prefix_ids"] = public_ip_prefix_ids
if resource_group_name is None and not opts.urn:
raise TypeError("Missing required property 'resource_group_name'")
__props__.__dict__["resource_group_name"] = resource_group_name
__props__.__dict__["sku_name"] = sku_name
__props__.__dict__["tags"] = tags
__props__.__dict__["zones"] = zones
__props__.__dict__["resource_guid"] = None
super(NatGateway, __self__).__init__(
'azure:network/natGateway:NatGateway',
resource_name,
__props__,
opts)
@staticmethod
def get(resource_name: str,
id: pulumi.Input[str],
opts: Optional[pulumi.ResourceOptions] = None,
idle_timeout_in_minutes: Optional[pulumi.Input[int]] = None,
location: Optional[pulumi.Input[str]] = None,
name: Optional[pulumi.Input[str]] = None,
public_ip_address_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
public_ip_prefix_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
resource_group_name: Optional[pulumi.Input[str]] = None,
resource_guid: Optional[pulumi.Input[str]] = None,
sku_name: Optional[pulumi.Input[str]] = None,
tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
zones: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None) -> 'NatGateway':
"""
Get an existing NatGateway resource's state with the given name, id, and optional extra
properties used to qualify the lookup.
:param str resource_name: The unique name of the resulting resource.
:param pulumi.Input[str] id: The unique provider ID of the resource to lookup.
:param pulumi.ResourceOptions opts: Options for the resource.
:param pulumi.Input[int] idle_timeout_in_minutes: The idle timeout which should be used in minutes. Defaults to `4`.
:param pulumi.Input[str] location: Specifies the supported Azure location where the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[str] name: Specifies the name of the NAT Gateway. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_address_ids: A list of Public IP Address ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[Sequence[pulumi.Input[str]]] public_ip_prefix_ids: / **Deprecated in favour of `network.NatGatewayPublicIpPrefixAssociation`**) A list of Public IP Prefix ID's which should be associated with the NAT Gateway resource.
:param pulumi.Input[str] resource_group_name: Specifies the name of the Resource Group in which the NAT Gateway should exist. Changing this forces a new resource to be created.
:param pulumi.Input[str] resource_guid: The resource GUID property of the NAT Gateway.
:param pulumi.Input[str] sku_name: The SKU which should be used. At this time the only supported value is `Standard`. Defaults to `Standard`.
:param pulumi.Input[Mapping[str, pulumi.Input[str]]] tags: A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
:param pulumi.Input[Sequence[pulumi.Input[str]]] zones: A list of availability zones where the NAT Gateway should be provisioned. Changing this forces a new resource to be created.
"""
opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))
__props__ = _NatGatewayState.__new__(_NatGatewayState)
__props__.__dict__["idle_timeout_in_minutes"] = idle_timeout_in_minutes
__props__.__dict__["location"] = location
__props__.__dict__["name"] = name
__props__.__dict__["public_ip_address_ids"] = public_ip_address_ids
__props__.__dict__["public_ip_prefix_ids"] = public_ip_prefix_ids
__props__.__dict__["resource_group_name"] = resource_group_name
__props__.__dict__["resource_guid"] = resource_guid
__props__.__dict__["sku_name"] = sku_name
__props__.__dict__["tags"] = tags
__props__.__dict__["zones"] = zones
return NatGateway(resource_name, opts=opts, __props__=__props__)
@property
@pulumi.getter(name="idleTimeoutInMinutes")
def idle_timeout_in_minutes(self) -> pulumi.Output[Optional[int]]:
"""
The idle timeout which should be used in minutes. Defaults to `4`.
"""
return pulumi.get(self, "idle_timeout_in_minutes")
@property
@pulumi.getter
def location(self) -> pulumi.Output[str]:
"""
Specifies the supported Azure location where the NAT Gateway should exist. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "location")
@property
@pulumi.getter
def name(self) -> pulumi.Output[str]:
"""
Specifies the name of the NAT Gateway. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "name")
@property
@pulumi.getter(name="publicIpAddressIds")
def public_ip_address_ids(self) -> pulumi.Output[Sequence[str]]:
"""
A list of Public IP Address ID's which should be associated with the NAT Gateway resource.
"""
return pulumi.get(self, "public_ip_address_ids")
@property
@pulumi.getter(name="publicIpPrefixIds")
def public_ip_prefix_ids(self) -> pulumi.Output[Sequence[str]]:
"""
/ **Deprecated in favour of `network.NatGatewayPublicIpPrefixAssociation`**) A list of Public IP Prefix ID's which should be associated with the NAT Gateway resource.
"""
return pulumi.get(self, "public_ip_prefix_ids")
@property
@pulumi.getter(name="resourceGroupName")
def resource_group_name(self) -> pulumi.Output[str]:
"""
Specifies the name of the Resource Group in which the NAT Gateway should exist. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "resource_group_name")
@property
@pulumi.getter(name="resourceGuid")
def resource_guid(self) -> pulumi.Output[str]:
"""
The resource GUID property of the NAT Gateway.
"""
return pulumi.get(self, "resource_guid")
@property
@pulumi.getter(name="skuName")
def sku_name(self) -> pulumi.Output[Optional[str]]:
"""
The SKU which should be used. At this time the only supported value is `Standard`. Defaults to `Standard`.
"""
return pulumi.get(self, "sku_name")
@property
@pulumi.getter
def tags(self) -> pulumi.Output[Optional[Mapping[str, str]]]:
"""
A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "tags")
@property
@pulumi.getter
def zones(self) -> pulumi.Output[Optional[Sequence[str]]]:
"""
A list of availability zones where the NAT Gateway should be provisioned. Changing this forces a new resource to be created.
"""
return pulumi.get(self, "zones")
|
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import random
import Convergence
from labellines import labelLines
matplotlib.use('TkAgg')
H0 = 70.0
c = 2.998E5
RADII = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,
0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0,
2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75,
4.0, 4.25, 4.5, 4.75, 5.0, 5.25, 5.5,
5.75, 6.0, 6.25, 6.5, 6.75, 7.0, 7.25,
7.5, 7.75, 8.0, 8.25, 8.5, 8.75, 9.0,
9.25, 9.5, 9.75, 10.0, 10.25, 10.5, 10.75,
11.0, 11.25, 11.5, 11.75, 12.0, 12.25, 12.5,
12.75, 13.0, 13.25, 13.5, 13.75, 14.0, 14.5,
15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0,
18.5, 19.0, 19.5, 20.0, 21.0, 22.0, 23.0,
24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0]
colours = [[0, 150/255, 100/255], [225/255, 149/255, 0], [207/255, 0, 48/255], 'C3', 'C4', 'C9', 'C6', 'C7', 'C8', 'C5']
grey = [0.75, 0.75, 0.75]
def vz(z):
q0 = -0.55
j0 = -1
return c * z * (1 + 0.5 * (1 - q0) * z - (1 - q0 - 3 * q0 ** 2 + j0) * (z ** 2) / 6)
v = c*0.1
zs = np.linspace(0, 1.5, 1001)
for num, theta in enumerate(np.array(RADII)[[0, 15, 27, 41, 57, 69, 76, 83]]):
theta_rad = theta / 60 * np.pi / 180.
Dperp = theta_rad * Convergence.comoving(zs, OM=0.25, OL=0.75, h=0.7) * 1000.0 / (1 + zs)
plt.plot(zs, Dperp, color=colours[0], alpha=(1 - num / 9.0), label=f"{theta}'", linewidth=1.5)
# labelLines(plt.gca().get_lines(), xvals=[1.375, 1.35, 1.32, 1.28, 1.23, 1.185, 1.11, 1.0],
labelLines(plt.gca().get_lines(), xvals=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
zorder=2.5, fontsize=12, align=False, color='k')
for num, theta in enumerate(np.array(RADII)[[0, 15, 27, 41, 57, 69, 76, 83]]):
theta_rad = theta / 60 * np.pi / 180.
Dperp = theta_rad * Convergence.comoving(zs[0:401], OM=0.27, OL=0.73, h=0.738) * 1000.0 / (1 + zs[0:401])
plt.plot(zs[:401], Dperp, color=colours[0], alpha=(1 - num / 9.0), label=f"{theta}'", linewidth=1.5, linestyle='--')
plt.fill_between([0, 1.5], [2, 2], [10, 10], color=colours[1], alpha=0.1, zorder=10)
kwargsMICE = {'color': colours[0], 'linestyle': '-'}
kwargsSDSS = {'color': colours[0], 'linestyle': '--'}
hMICE, = plt.plot([], [], **kwargsMICE)
hSDSS, = plt.plot([], [], **kwargsSDSS)
plt.legend((hMICE, hSDSS),('MICE', 'SDSS'), frameon=0)
plt.plot([0.6, 0.6], [-5, 45], linestyle='--', color=grey)
# plt.text(0.4, 15, 'SDSS', color=grey, fontsize=16)
plt.ylim([-1, 18])
plt.xlim([0, 1.5])
plt.xlabel('$z$')
plt.ylabel('Perpendicular Distance (Mpc)')
plt.show()
n = 41
mag = np.ones(n)
magdeg = np.zeros(n)
magdegplus = np.zeros(n)
for i in np.arange(n):
magdeg[i] = mag[i] * random.gauss(1.0, 0.1)
magdegplus[i] = mag[i] + random.gauss(0.0, 0.1)
plt.plot(mag, '.')
# plt.plot(magdeg,'x')
# plt.plot(magdegplus,'+')
plt.errorbar(np.arange(n), magdegplus, np.ones(n)*0.1, fmt='.')
# plt.errorbar(np.arange(n),magdeg,np.ones(11)*0.1,'.')
plt.show()
|
#!/usr/bin/env python3
"""
This is a script to append an Archivematica UUID as
an Internal-Sender-Identifier to existing born-digital bags.
When run this will create a "target" folder in the same directory
to work within. It will leave "some_bag_id.log" files for each
bag it migrates.
"""
import datetime
import hashlib
import os
import shutil
import sys
from uuid import UUID
from elasticsearch import helpers
import tqdm
from common import get_aws_client, get_storage_client, get_elastic_client
def generate_checksum(file_location):
sha256_hash = hashlib.sha256()
with open(file_location, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
def compress_folder(folder, remove_folder=True):
archive_name = shutil.make_archive(folder, "gztar", folder)
if remove_folder:
shutil.rmtree(folder, ignore_errors=True)
return archive_name
def filter_s3_objects(s3_client, bucket, prefix):
response = s3_client.list_objects_v2(Bucket=bucket, Prefix=prefix)
if "Contents" in response:
return [content["Key"] for content in response["Contents"]]
else:
return []
def read_tag_file(file_location, delimiter=" ", key_first=True):
fields = {}
with open(file_location) as fp:
for line in fp:
first, second = line.split(delimiter, 1)
if key_first:
fields[first.strip()] = second.strip()
else:
fields[second.strip()] = first.strip()
return fields
def write_tag_file(file_location, fields):
with open(file_location, "w") as fp:
for key, value in fields.items():
fp.write(f"{key}: {value}\n")
class SimpleLog:
def __init__(self, log_location, init_msg):
self.log_location = log_location
# Initialise working log
with open(log_location, "w") as fp:
fp.write(f"{datetime.datetime.now().isoformat()}: {init_msg}\n")
def log(self, msg):
with open(self.log_location, "a") as fp:
fp.write(f"{datetime.datetime.now().isoformat()}: {msg}\n")
class ArchivematicaUUIDBagMigrator:
def __init__(
self,
workflow_s3_client,
storage_s3_client,
storage_client,
s3_upload_bucket,
target_folder,
):
self.workflow_s3_client = workflow_s3_client
self.storage_s3_client = storage_s3_client
self.storage_client = storage_client
self.s3_upload_bucket = s3_upload_bucket
self.target_folder = target_folder
self.tagmanifest_name = "tagmanifest-sha256.txt"
self.s3_upload_prefix = "born-digital/archivematica-uuid-update"
@staticmethod
def _get_archivematica_uuid(files):
mets_files = [
f["name"]
for f in files
if f["name"].startswith("data/METS.") and f["name"].endswith(".xml")
]
assert len(mets_files) == 1, "No UUID found in METS file"
mets_file_with_id = mets_files[0]
archivematica_uuid = mets_file_with_id.split("/METS.")[-1].split(".xml")[0]
assert UUID(archivematica_uuid, version=4)
return archivematica_uuid
@staticmethod
def _generate_updated_checksums(working_folder):
files_in_need_of_update = ["bag-info.txt", "fetch.txt"]
return {
filename: generate_checksum(f"{working_folder}/{filename}")
for filename in files_in_need_of_update
}
def _load_existing_checksums(self, working_folder):
tag_manifest = read_tag_file(
file_location=f"{working_folder}/{self.tagmanifest_name}", key_first=False
)
files_that_should_be_referenced = [
"bag-info.txt",
"bagit.txt",
"manifest-sha256.txt",
]
assert any(
filename in files_that_should_be_referenced
for filename in tag_manifest.keys()
), "Missing file while loading checksums"
return tag_manifest
@staticmethod
def _write_fetch_file(bucket, path, working_folder, files):
path_prefix = f"s3://{bucket}/{path}"
with open(f"{working_folder}/fetch.txt", "w") as fetch_file:
for file in files:
s3_uri = f"{path_prefix}/{file['path']}"
fetch_file.write(f"{s3_uri}\t{file['size']}\t{file['name']}\n")
@staticmethod
def _get_bagit_files_from_s3(
bucket, path, version, working_folder, tagmanifest_files
):
for file in tagmanifest_files:
location = f"{path}/{version}/{file['name']}"
save_path = f"{working_folder}/{file['name']}"
storage_s3_client.download_file(bucket, location, save_path)
@staticmethod
def _append_archivematica_uuid(working_folder, archivematica_uuid):
bag_info = read_tag_file(
file_location=f"{working_folder}/bag-info.txt", delimiter=": "
)
assert (
"Internal-Sender-Identifier:" not in bag_info
), "Found Internal-Sender-Identifier in bag-info.txt"
bag_info["Internal-Sender-Identifier"] = archivematica_uuid
bag_info_path = os.path.join(working_folder, "bag-info.txt")
write_tag_file(bag_info_path, bag_info)
def _update_tagmanifest(self, working_folder):
existing_checksums = self._load_existing_checksums(working_folder)
new_checksums = self._generate_updated_checksums(working_folder)
merged_checksums = dict(existing_checksums)
for k, v in new_checksums.items():
merged_checksums[k] = v
assert (
"fetch.txt" in merged_checksums.keys()
), "fetch.txt not found in merged checksums"
old_bag_info_checksum = existing_checksums.get("bag-info.txt")
new_bag_info_checksum = merged_checksums.get("bag-info.txt")
assert (
old_bag_info_checksum != new_bag_info_checksum
), "bag-info.txt checksum is incorrect"
with open(f"{working_folder}/{self.tagmanifest_name}", "w") as fp:
for checksum, filename in merged_checksums.items():
fp.write(f"{filename} {checksum}\n")
def _upload_bag_to_s3(self, archive_location, working_id, remove_bag=True):
s3_upload_key = f"{self.s3_upload_prefix}/{working_id}.tar.gz"
workflow_s3_client.upload_file(
Filename=archive_location, Bucket=s3_upload_bucket, Key=s3_upload_key
)
if remove_bag:
os.remove(archive_location)
return s3_upload_key
def migrate(self, version, space, external_identifier):
storage_manifest = storage_client.get_bag(
space=space, external_identifier=external_identifier, version=version
)
id = storage_manifest["id"]
bucket = storage_manifest["location"]["bucket"]
path = storage_manifest["location"]["path"]
payload_files = storage_manifest["manifest"]["files"]
provider = storage_manifest["location"]["provider"]["id"]
tagmanifest_files = storage_manifest["tagManifest"]["files"]
internal_identifier = storage_manifest["info"].get("internalSenderIdentifier")
assert provider == "amazon-s3", f"Provider must be amazon-s3, found {provider}"
assert (
internal_identifier is None
), f"Internal identifier found: {internal_identifier}"
working_id = id.replace("/", "_")
working_folder = os.path.join(self.target_folder, working_id)
os.makedirs(working_folder, exist_ok=True)
logger = SimpleLog(
log_location=os.path.join(self.target_folder, f"{working_id}.log"),
init_msg=f"Starting migration for {id}",
)
# Write fetch.txt
self._write_fetch_file(
working_folder=working_folder, bucket=bucket, path=path, files=payload_files
)
logger.log(f"Wrote fetch.txt")
# Get required files from bag
self._get_bagit_files_from_s3(
working_folder=working_folder,
bucket=bucket,
path=path,
version=version,
tagmanifest_files=tagmanifest_files,
)
logger.log(f"Got BagIt files from S3")
# Update bag-info.txt
archivematica_uuid = self._get_archivematica_uuid(files=payload_files)
self._append_archivematica_uuid(working_folder, archivematica_uuid)
logger.log(
f"Appended Internal-Sender-Identifier to bag-info.txt: {archivematica_uuid}"
)
# Update tagmanifest-sha256.txt
self._update_tagmanifest(working_folder=working_folder)
logger.log(f"Updated {self.tagmanifest_name}")
# Create compressed bag
archive_location = compress_folder(folder=working_folder)
logger.log(f"Created archive: {archive_location}")
# Upload compressed bag to S3
s3_upload_key = self._upload_bag_to_s3(
archive_location=archive_location, working_id=working_id
)
logger.log(f"Uploaded bag to s3://{s3_upload_bucket}/{s3_upload_key}")
# Request ingest of uploaded bag from Storage Service
ingest_uri = storage_client.create_s3_ingest(
space=space,
external_identifier=external_identifier,
s3_bucket=s3_upload_bucket,
s3_key=s3_upload_key,
ingest_type="update",
)
logger.log(f"Requested ingest: {ingest_uri}")
logger.log(f"Completed migration for {id}")
if __name__ == "__main__":
try:
environment_id = sys.argv[1]
document_limit = int(sys.argv[2])
except IndexError:
sys.exit(f"Usage: {__file__} <ENVIRONMENT> <DOCUMENT_COUNT>")
storage_role_arn = "arn:aws:iam::975596993436:role/storage-developer"
workflow_role_arn = "arn:aws:iam::299497370133:role/workflow-developer"
elastic_secret_id = "archivematica_bags_migration/credentials"
target_folder = "target"
environments = {
"prod": {
"bucket": "wellcomecollection-archivematica-ingests",
"api_url": "https://api.wellcomecollection.org/storage/v1",
"reporting_index": "storage_bags",
},
"stage": {
"bucket": "wellcomecollection-archivematica-staging-ingests",
"api_url": "https://api-stage.wellcomecollection.org/storage/v1",
"reporting_index": "storage_stage_bags",
},
}
api_url = environments[environment_id]["api_url"]
index = environments[environment_id]["reporting_index"]
s3_upload_bucket = environments[environment_id]["bucket"]
workflow_s3_client = get_aws_client(resource="s3", role_arn=workflow_role_arn)
storage_s3_client = get_aws_client(resource="s3", role_arn=storage_role_arn)
elastic_client = get_elastic_client(
role_arn=storage_role_arn, elastic_secret_id=elastic_secret_id
)
storage_client = get_storage_client(api_url=api_url)
elastic_query = {
"query": {
"bool": {
"must": {"prefix": {"space": {"value": "born-digital"}}},
"must_not": [{"exists": {"field": "info.internalSenderIdentifier"}}],
}
}
}
bag_migrator = ArchivematicaUUIDBagMigrator(
workflow_s3_client=workflow_s3_client,
storage_s3_client=storage_s3_client,
storage_client=storage_client,
s3_upload_bucket=s3_upload_bucket,
target_folder=target_folder,
)
initial_query = elastic_client.search(index=index, body=elastic_query, size=0)
document_count = initial_query["hits"]["total"]["value"]
documents_to_process = min([document_limit, document_count])
print(f"Found {document_count} to process, limit is {document_limit}.")
results = helpers.scan(
client=elastic_client, index=index, size=5, query=elastic_query
)
os.makedirs(target_folder, exist_ok=True)
logger = SimpleLog(
log_location=os.path.join(target_folder, f"error.log"),
init_msg=f"Starting migration of {documents_to_process} bags",
)
tqdm_iterator = tqdm.tqdm(results, total=documents_to_process)
processed_documents = 0
for result in tqdm_iterator:
if processed_documents == documents_to_process:
tqdm_iterator.close()
break
document = result["_source"]
id = document["id"]
version = f"v{document['version']}"
space = document["space"]
external_identifier = document["info"]["externalIdentifier"]
try:
bag_migrator.migrate(
version=version, space=space, external_identifier=external_identifier
)
except Exception as err:
logger.log(f"{id}: {err}")
processed_documents = processed_documents + 1
|
import unittest
import numpy as np
import scipy.signal
import ibllib.dsp.fourier as ft
from ibllib.dsp import WindowGenerator, rms, rises, falls, fronts, smooth, shift, fit_phase,\
fcn_cosine
class TestDspMisc(unittest.TestCase):
def test_dsp_cosine_func(self):
x = np.linspace(0, 40)
fcn = fcn_cosine(bounds=[20, 30])
y = fcn(x)
self.assertTrue(y[0] == 0 and y[-1] == 1 and np.all(np.diff(y) >= 0))
class TestPhaseRegression(unittest.TestCase):
def test_fit_phase1d(self):
w = np.zeros(500)
w[1] = 1
self.assertTrue(np.isclose(fit_phase(w, .002), .002))
def test_fit_phase2d(self):
w = np.zeros((500, 2))
w[1, 0], w[2, 1] = (1, 1)
self.assertTrue(np.all(np.isclose(fit_phase(w, .002, axis=0), np.array([.002, .004]))))
self.assertTrue(np.all(np.isclose(fit_phase(w.transpose(), .002), np.array([.002, .004]))))
class TestShift(unittest.TestCase):
def test_shift_1d(self):
ns = 500
w = scipy.signal.ricker(ns, 10)
self.assertTrue(np.all(np.isclose(shift(w, 1), np.roll(w, 1))))
def test_shift_2d(self):
ns = 500
w = scipy.signal.ricker(ns, 10)
w = np.tile(w, (100, 1)).transpose()
self.assertTrue(np.all(np.isclose(shift(w, 1, axis=0), np.roll(w, 1, axis=0))))
self.assertTrue(np.all(np.isclose(shift(w, 1, axis=1), np.roll(w, 1, axis=1))))
class TestSmooth(unittest.TestCase):
def test_smooth_lp(self):
np.random.seed(458)
a = np.random.rand(500,)
a_ = smooth.lp(a, [0.1, 0.15])
res = ft.hp(np.pad(a_, 100, mode='edge'), 1, [0.1, 0.15])[100:-100]
self.assertTrue((rms(a) / rms(res)) > 500)
class TestFFT(unittest.TestCase):
def test_spectral_convolution(self):
sig = np.random.randn(20, 500)
w = np.hanning(25)
c = ft.convolve(sig, w)
s = np.convolve(sig[0, :], w)
self.assertTrue(np.all(np.isclose(s, c[0, :-1])))
c = ft.convolve(sig, w, mode='same')
s = np.convolve(sig[0, :], w, mode='same')
self.assertTrue(np.all(np.isclose(c[0, :], s)))
c = ft.convolve(sig, w[:-1], mode='same')
s = np.convolve(sig[0, :], w[:-1], mode='same')
self.assertTrue(np.all(np.isclose(c[0, :], s)))
def test_nech_optim(self):
self.assertTrue(ft.ns_optim_fft(2048) == 2048)
self.assertTrue(ft.ns_optim_fft(65532) == 65536)
def test_imports(self):
import ibllib.dsp as dsp
self.assertTrue(len([dsp.lp,
dsp.fexpand,
dsp.hp,
dsp.fscale,
dsp.freduce,
dsp.rms]) == 6)
def test_freduce(self):
# test with 1D arrays
fs = np.fft.fftfreq(5)
self.assertTrue(np.all(ft.freduce(fs) == fs[:-2]))
fs = np.fft.fftfreq(6)
self.assertTrue(np.all(ft.freduce(fs) == fs[:-2]))
# test 2D arrays along both dimensions
fs = np.tile(ft.fscale(500, 0.001), (4, 1))
self.assertTrue(ft.freduce(fs).shape == (4, 251))
self.assertTrue(ft.freduce(np.transpose(fs), axis=0).shape == (251, 4))
def test_fexpand(self):
# test odd input
res = np.random.rand(11)
X = ft.freduce(np.fft.fft(res))
R = np.real(np.fft.ifft(ft.fexpand(X, 11)))
self.assertTrue(np.all((res - R) < 1e-6))
# test even input
res = np.random.rand(12)
X = ft.freduce(np.fft.fft(res))
R = np.real(np.fft.ifft(ft.fexpand(X, 12)))
self.assertTrue(np.all((res - R) < 1e-6))
# test with a 2 dimensional input along last dimension
res = np.random.rand(2, 12)
X = ft.freduce(np.fft.fft(res))
R = np.real(np.fft.ifft(ft.fexpand(X, 12)))
self.assertTrue(np.all((res - R) < 1e-6))
# test with a 3 dimensional input along last dimension
res = np.random.rand(3, 5, 12)
X = ft.freduce(np.fft.fft(res))
R = np.real(np.fft.ifft(ft.fexpand(X, 12)))
self.assertTrue(np.all((res - R) < 1e-6))
# test with 2 dimensional input along first dimension
fs = np.transpose(np.tile(ft.fscale(500, 0.001, one_sided=True), (4, 1)))
self.assertTrue(ft.fexpand(fs, 500, axis=0).shape == (500, 4))
def test_fscale(self):
# test for an even number of samples
res = [0, 100, 200, 300, 400, 500, -400, -300, -200, -100],
self.assertTrue(np.all(np.abs(ft.fscale(10, 0.001) - res) < 1e-6))
# test for an odd number of samples
res = [0, 90.9090909090909, 181.818181818182, 272.727272727273, 363.636363636364,
454.545454545455, -454.545454545455, -363.636363636364, -272.727272727273,
-181.818181818182, -90.9090909090909],
self.assertTrue(np.all(np.abs(ft.fscale(11, 0.001) - res) < 1e-6))
def test_filter_lp_hp(self):
# test 1D time serie: subtracting lp filter removes DC
ts1 = np.random.rand(500)
out1 = ft.lp(ts1, 1, [.1, .2])
self.assertTrue(np.mean(ts1 - out1) < 0.001)
# test 2D case along the last dimension
ts = np.tile(ts1, (11, 1))
out = ft.lp(ts, 1, [.1, .2])
self.assertTrue(np.allclose(out, out1))
# test 2D case along the first dimension
ts = np.tile(ts1[:, np.newaxis], (1, 11))
out = ft.lp(ts, 1, [.1, .2], axis=0)
self.assertTrue(np.allclose(np.transpose(out), out1))
# test 1D time serie: subtracting lp filter removes DC
out2 = ft.hp(ts1, 1, [.1, .2])
self.assertTrue(np.allclose(out1, ts1 - out2))
def test_dft(self):
# test 1D complex
x = np.array([1, 2 - 1j, -1j, -1 + 2j])
X = ft.dft(x)
assert np.all(np.isclose(X, np.fft.fft(x)))
# test 1D real
x = np.random.randn(7)
X = ft.dft(x)
assert np.all(np.isclose(X, np.fft.rfft(x)))
# test along the 3 dimensions of a 3D array
x = np.random.rand(10, 11, 12)
for axis in np.arange(3):
X_ = np.fft.rfft(x, axis=axis)
assert np.all(np.isclose(X_, ft.dft(x, axis=axis)))
# test 2D irregular grid
_n0, _n1, nt = (10, 11, 30)
x = np.random.rand(_n0 * _n1, nt)
X_ = np.fft.fft(np.fft.fft(x.reshape(_n0, _n1, nt), axis=0), axis=1)
r, c = [v.flatten() for v in np.meshgrid(np.arange(
_n0) / _n0, np.arange(_n1) / _n1, indexing='ij')]
nk, nl = (_n0, _n1)
X = ft.dft2(x, r, c, nk, nl)
assert np.all(np.isclose(X, X_))
class TestWindowGenerator(unittest.TestCase):
def test_window_simple(self):
wg = WindowGenerator(ns=500, nswin=100, overlap=50)
sl = list(wg.firstlast)
self.assertTrue(wg.nwin == len(sl) == 9)
self.assertTrue(np.all(np.array([s[0] for s in sl]) == np.arange(0, wg.nwin) * 50))
self.assertTrue(np.all(np.array([s[1] for s in sl]) == np.arange(0, wg.nwin) * 50 + 100))
wg = WindowGenerator(ns=500, nswin=100, overlap=10)
sl = list(wg.firstlast)
first = np.array([0, 90, 180, 270, 360, 450])
last = np.array([100, 190, 280, 370, 460, 500])
self.assertTrue(wg.nwin == len(sl) == 6)
self.assertTrue(np.all(np.array([s[0] for s in sl]) == first))
self.assertTrue(np.all(np.array([s[1] for s in sl]) == last))
def test_nwindows_computation(self):
for m in np.arange(0, 100):
wg = WindowGenerator(ns=500 + m, nswin=87 + m, overlap=11 + m)
sl = list(wg.firstlast)
self.assertTrue(wg.nwin == len(sl))
def test_firstlast_slices(self):
# test also the indexing versus direct slicing
my_sig = np.random.rand(500,)
wg = WindowGenerator(ns=500, nswin=100, overlap=50)
# 1) get the window by
my_rms = np.zeros((wg.nwin,))
for first, last in wg.firstlast:
my_rms[wg.iw] = rms(my_sig[first:last])
# test with slice_array method
my_rms_ = np.zeros((wg.nwin,))
for wsig in wg.slice_array(my_sig):
my_rms_[wg.iw] = rms(wsig)
self.assertTrue(np.all(my_rms_ == my_rms))
# test with the slice output
my_rms_ = np.zeros((wg.nwin,))
for sl in wg.slice:
my_rms_[wg.iw] = rms(my_sig[sl])
self.assertTrue(np.all(my_rms_ == my_rms))
def test_tscale(self):
wg = WindowGenerator(ns=500, nswin=100, overlap=50)
ts = wg.tscale(fs=1000)
self.assertTrue(ts[0] == (100 - 1) / 2 / 1000)
self.assertTrue((np.allclose(np.diff(ts), 0.05)))
def test_rises_falls(self):
# test 1D case with a long pulse and a dirac
a = np.zeros(500,)
a[80:120] = 1
a[200] = 1
# rising fronts
self.assertTrue(all(rises(a) == np.array([80, 200])))
# falling fronts
self.assertTrue(all(falls(a) == np.array([120, 201])))
# both
ind, val = fronts(a)
self.assertTrue(all(ind == np.array([80, 120, 200, 201])))
self.assertTrue(all(val == np.array([1, -1, 1, -1])))
# test a 2D case with 2 long pulses and a dirac
a = np.zeros((2, 500))
a[0, 80:120] = 1
a[0, 200] = 1
a[1, 280:320] = 1
a[1, 400] = 1
# rising fronts
self.assertTrue(np.all(rises(a) == np.array([[0, 0, 1, 1], [80, 200, 280, 400]])))
# falling fronts
self.assertTrue(np.all(falls(a) == np.array([[0, 0, 1, 1], [120, 201, 320, 401]])))
# both
ind, val = fronts(a)
self.assertTrue(all(ind[0] == np.array([0, 0, 0, 0, 1, 1, 1, 1])))
self.assertTrue(all(ind[1] == np.array([80, 120, 200, 201, 280, 320, 400, 401])))
self.assertTrue(all(val == np.array([1, -1, 1, -1, 1, -1, 1, -1])))
if __name__ == "__main__":
unittest.main(exit=False)
|
# built-in
from itertools import islice, permutations, repeat
from math import log
# app
from .base import Base as _Base, BaseSimilarity as _BaseSimilarity
from .edit_based import DamerauLevenshtein
# python3
try:
from functools import reduce
except ImportError:
pass
__all__ = [
'Jaccard', 'Sorensen', 'Tversky',
'Overlap', 'Cosine', 'Tanimoto', 'MongeElkan', 'Bag',
'jaccard', 'sorensen', 'tversky', 'sorensen_dice',
'overlap', 'cosine', 'tanimoto', 'monge_elkan', 'bag',
]
class Jaccard(_BaseSimilarity):
"""
Compute the Jaccard similarity between the two sequences.
They should contain hashable items.
The return value is a float between 0 and 1, where 1 means equal,
and 0 totally different.
https://en.wikipedia.org/wiki/Jaccard_index
https://github.com/Yomguithereal/talisman/blob/master/src/metrics/distance/jaccard.js
"""
def __init__(self, qval=1, as_set=False, external=True):
self.qval = qval
self.as_set = as_set
self.external = external
def maximum(self, *sequences):
return 1
def __call__(self, *sequences):
result = self.quick_answer(*sequences)
if result is not None:
return result
sequences = self._get_counters(*sequences) # sets
intersection = self._intersect_counters(*sequences) # set
intersection = self._count_counters(intersection) # int
union = self._union_counters(*sequences) # set
union = self._count_counters(union) # int
return intersection / float(union)
class Sorensen(_BaseSimilarity):
"""
Compute the Sorensen distance between the two sequences.
They should contain hashable items.
The return value is a float between 0 and 1, where 0 means equal,
and 1 totally different.
https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient
https://github.com/Yomguithereal/talisman/blob/master/src/metrics/distance/dice.js
"""
def __init__(self, qval=1, as_set=False):
self.qval = qval
self.as_set = as_set
def maximum(self, *sequences):
return 1
def __call__(self, *sequences):
result = self.quick_answer(*sequences)
if result is not None:
return result
sequences = self._get_counters(*sequences) # sets
count = sum(self._count_counters(s) for s in sequences)
intersection = self._intersect_counters(*sequences) # set
intersection = self._count_counters(intersection) # int
return 2.0 * intersection / count
class Tversky(_BaseSimilarity):
"""Tversky index
https://en.wikipedia.org/wiki/Tversky_index
https://github.com/Yomguithereal/talisman/blob/master/src/metrics/distance/tversky.js
"""
def __init__(self, qval=1, ks=None, bias=None, as_set=False, external=True):
self.qval = qval
self.ks = ks or repeat(1)
self.bias = bias
self.as_set = as_set
self.external = external
def maximum(self, *sequences):
return 1
def __call__(self, *sequences):
result = self.quick_answer(*sequences)
if result is not None:
return result
sequences = self._get_counters(*sequences) # sets
intersection = self._intersect_counters(*sequences) # set
intersection = self._count_counters(intersection) # int
sequences = [self._count_counters(s) for s in sequences] # ints
ks = list(islice(self.ks, len(sequences)))
if len(sequences) == 2 or self.bias is None:
result = intersection
for k, s in zip(ks, sequences):
result += k * (s - intersection)
return float(intersection) / result
s1, s2 = sequences
alpha, beta = ks
a_val = min([s1, s2])
b_val = max([s1, s2])
c_val = float(intersection + self.bias)
result = alpha * beta * (a_val - b_val) + b_val * beta
return c_val / (result + c_val)
class Overlap(_BaseSimilarity):
"""overlap coefficient
https://en.wikipedia.org/wiki/Overlap_coefficient
https://github.com/Yomguithereal/talisman/blob/master/src/metrics/distance/overlap.js
"""
def __init__(self, qval=1, as_set=False, external=True):
self.qval = qval
self.as_set = as_set
self.external = external
def maximum(self, *sequences):
return 1
def __call__(self, *sequences):
result = self.quick_answer(*sequences)
if result is not None:
return result
sequences = self._get_counters(*sequences) # sets
intersection = self._intersect_counters(*sequences) # set
intersection = self._count_counters(intersection) # int
sequences = [self._count_counters(s) for s in sequences] # ints
return float(intersection) / min(sequences)
class Cosine(_BaseSimilarity):
"""cosine similarity (Ochiai coefficient)
https://en.wikipedia.org/wiki/Cosine_similarity
https://github.com/Yomguithereal/talisman/blob/master/src/metrics/distance/cosine.js
"""
def __init__(self, qval=1, as_set=False):
self.qval = qval
self.as_set = as_set
def maximum(self, *sequences):
return 1
def __call__(self, *sequences):
result = self.quick_answer(*sequences)
if result is not None:
return result
sequences = self._get_counters(*sequences) # sets
intersection = self._intersect_counters(*sequences) # set
intersection = self._count_counters(intersection) # int
sequences = [self._count_counters(s) for s in sequences] # ints
prod = reduce(lambda x, y: x * y, sequences)
return intersection / pow(prod, 1.0 / len(sequences))
class Tanimoto(Jaccard):
"""Tanimoto distance
This is identical to the Jaccard similarity coefficient
and the Tversky index for alpha=1 and beta=1.
"""
def __call__(self, *sequences):
result = super(Tanimoto, self).__call__(*sequences)
if result == 0:
return float('-inf')
else:
return log(result, 2)
class MongeElkan(_BaseSimilarity):
"""
https://www.academia.edu/200314/Generalized_Monge-Elkan_Method_for_Approximate_Text_String_Comparison
http://www.cs.cmu.edu/~wcohen/postscript/kdd-2003-match-ws.pdf
https://github.com/Yomguithereal/talisman/blob/master/src/metrics/distance/monge-elkan.js
"""
_damerau_levenshtein = DamerauLevenshtein()
def __init__(self, algorithm=_damerau_levenshtein, symmetric=False, qval=1):
self.algorithm = algorithm
self.symmetric = symmetric
self.qval = qval
def maximum(self, *sequences):
result = self.algorithm.maximum(sequences)
for seq in sequences:
if seq:
result = max(result, self.algorithm.maximum(*seq))
return result
def _calc(self, seq, *sequences):
if not seq:
return 0
maxes = []
for c1 in seq:
for s in sequences:
max_sim = float('-inf')
for c2 in s:
max_sim = max(max_sim, self.algorithm.similarity(c1, c2))
maxes.append(max_sim)
return float(sum(maxes)) / len(seq) / len(maxes)
def __call__(self, *sequences):
result = self.quick_answer(*sequences)
if result is not None:
return result
sequences = self._get_sequences(*sequences)
if self.symmetric:
result = []
for seqs in permutations(sequences):
result.append(self._calc(*seqs))
return float(sum(result)) / len(result)
else:
return self._calc(*sequences)
class Bag(_Base):
"""Bag distance
https://github.com/Yomguithereal/talisman/blob/master/src/metrics/distance/bag.js
"""
def __call__(self, *sequences):
sequences = self._get_counters(*sequences) # sets
intersection = self._intersect_counters(*sequences) # set
sequences = (self._count_counters(sequence - intersection) for sequence in sequences)
# ^ ints
return max(sequences)
bag = Bag()
cosine = Cosine()
dice = Sorensen()
jaccard = Jaccard()
monge_elkan = MongeElkan()
overlap = Overlap()
sorensen = Sorensen()
sorensen_dice = Sorensen()
# sorensen_dice = Tversky(ks=[.5, .5])
tanimoto = Tanimoto()
tversky = Tversky()
|
<reponame>mahen92/Hyperledger-Cookbook
# Copyright 2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
import hashlib
import sys
import os
import argparse
import pkg_resources
from sawtooth_sdk.processor.core import TransactionProcessor
from sawtooth_sdk.processor.log import init_console_logging
from sawtooth_sdk.processor.log import log_configuration
from sawtooth_sdk.processor.config import get_log_config
from sawtooth_sdk.processor.config import get_log_dir
from sawtooth_sdk.processor.config import get_config_dir
from sawtooth_mkt.processor.handler import MktTransactionHandler
from sawtooth_mkt.processor.config.mkt import MktConfig
from sawtooth_mkt.processor.config.mkt import \
load_default_mkt_config
from sawtooth_mkt.processor.config.mkt import \
load_toml_mkt_config
from sawtooth_mkt.processor.config.mkt import \
merge_mkt_config
DISTRIBUTION_NAME = 'sawtooth-mkt'
def parse_args(args):
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'-C', '--connect',
help='Endpoint for the validator connection')
parser.add_argument('-v', '--verbose',
action='count',
default=0,
help='Increase output sent to stderr')
try:
version = pkg_resources.get_distribution(DISTRIBUTION_NAME).version
except pkg_resources.DistributionNotFound:
version = 'UNKNOWN'
parser.add_argument(
'-V', '--version',
action='version',
version=(DISTRIBUTION_NAME + ' (Hyperledger Sawtooth) version {}')
.format(version),
help='print version information')
return parser.parse_args(args)
def load_mkt_config(first_config):
default_mkt_config = \
load_default_mkt_config()
conf_file = os.path.join(get_config_dir(), 'mkt.toml')
toml_config = load_toml_mkt_config(conf_file)
return merge_mkt_config(
configs=[first_config, toml_config, default_mkt_config])
def create_mkt_config(args):
return MktConfig(connect=args.connect)
def main(args=None):
if args is None:
args = sys.argv[1:]
opts = parse_args(args)
processor = None
try:
arg_config = create_mkt_config(opts)
mkt_config = load_mkt_config(arg_config)
processor = TransactionProcessor(url=mkt_config.connect)
log_config = get_log_config(filename="mkt_log_config.toml")
# If no toml, try loading yaml
if log_config is None:
log_config = get_log_config(filename="mkt_log_config.yaml")
if log_config is not None:
log_configuration(log_config=log_config)
else:
log_dir = get_log_dir()
# use the transaction processor zmq identity for filename
log_configuration(
log_dir=log_dir,
name="mkt-" + str(processor.zmq_id)[2:-1])
init_console_logging(verbose_level=opts.verbose)
# The prefix should eventually be looked up from the
# validator's namespace registry.
mkt_prefix = hashlib.sha512('mkt'.encode("utf-8")).hexdigest()[0:6]
handler = MktTransactionHandler(namespace_prefix=mkt_prefix)
processor.add_handler(handler)
processor.start()
except KeyboardInterrupt:
pass
except Exception as e: # pylint: disable=broad-except
print("Error: {}".format(e))
finally:
if processor is not None:
processor.stop()
|
<reponame>shyams2/pychebfun
#!/usr/bin/env python
# coding: UTF-8
from __future__ import division
import os
import sys
import unittest
import numpy as np
import numpy.testing as npt
import pychebfun
from pychebfun import Chebfun, chebfun
from . import tools
import pytest
np.seterr(all='raise')
def segment(x):
y = np.expand_dims(x, axis=-1)
zeros = np.zeros_like(y)
return np.concatenate([y, zeros], axis=-1)
class TestSegment(unittest.TestCase):
def setUp(self):
self.fun = segment
def test_shape(self):
val = self.fun(0.)
self.assertEqual(val.shape, (2,))
valv = self.fun(np.arange(3.))
self.assertEqual(valv.shape, (3,2))
class TestCircle(TestSegment):
def setUp(self):
self.fun = tools.circle
def Quad(x):
return x*x
def piecewise_continuous(x):
"""
The function is on the verge of being discontinuous at many points
"""
return np.exp(x)*np.sin(3*x)*np.tanh(5*np.cos(30*x))
def runge(x):
return 1./(1+25*x**2)
class Test_chebfuninit(unittest.TestCase):
"""
Test that the initialisation function chebfun works as expected.
"""
def test_from_function(self):
cr = chebfun(tools.f)
ce = Chebfun.from_function(tools.f)
tools.assert_close(cr, ce)
def test_from_chebcoeffs(self):
coeffs = np.random.randn(10)
cr = chebfun(chebcoeff=coeffs)
ce = Chebfun.from_coeff(coeffs)
tools.assert_close(cr, ce)
def test_from_chebfun(self):
ce = Chebfun.from_function(tools.f)
cr = chebfun(ce)
tools.assert_close(cr, ce)
def test_from_values(self):
values = np.random.randn(10)
cr = chebfun(values)
ce = Chebfun.from_data(values)
tools.assert_close(cr, ce)
def test_from_scalar(self):
val = np.random.rand()
cr = chebfun(val)
ce = Chebfun.from_data([val])
tools.assert_close(cr, ce)
def test_error(self):
"""
Error if chebfun is called with another type.
"""
class C(object):
pass
with self.assertRaises(TypeError):
chebfun(C())
class Test_sinsinexp(unittest.TestCase):
"""
Tests with function np.sin(6*x) + np.sin(30*np.exp(x))
"""
def setUp(self):
# Construct the O(dx^-16) "spectrally accurate" chebfun p
self.p = Chebfun.from_function(tools.f)
def test_biglen(self):
self.assertGreaterEqual(self.p.size(), 4)
def test_len(self):
"""
Length of chebfun is equal to the number of Cheb coefficients (i.e., degree)
"""
self.assertEqual(self.p.size(), len(self.p.coefficients()))
def test_error(self):
"""
Chebfun is closed to function f up to tolerance
"""
tools.assert_close(self.p, tools.f, atol=1e-13)
def test_root(self):
"""
Roots are zeros of the chebfun.
"""
roots = self.p.roots()
npt.assert_array_almost_equal(tools.f(roots),0)
def test_all_roots(self):
"""
Capture all rots.
"""
roots = self.p.roots()
self.assertEqual(len(roots),22)
def test_chebcoeff(self):
new = Chebfun.from_coeff(self.p.coefficients())
tools.assert_close(self.p, new)
def test_prod(self):
"""
Product p*p is correct.
"""
pp = self.p*self.p
tools.assert_close(lambda x: self.p(x)*self.p(x), pp, atol=1e-13)
def test_square(self):
def square(x):
return self.p(x)*self.p(x)
sq = Chebfun.from_function(square)
npt.assert_array_less(0, sq(tools.xs))
self.sq = sq
def test_chebyshev_points(self):
"""
First and last interpolation points are -1 and 1
"""
N = pow(2,5)
pts = Chebfun.interpolation_points(N)
npt.assert_array_almost_equal(pts[[0,-1]],np.array([1.,-1]))
def test_N(self):
"""
Check initialisation with a fixed N
"""
N = self.p.size() - 1
pN = Chebfun.from_function(tools.f, N=N)
self.assertEqual(len(pN.coefficients()), N+1)
self.assertEqual(len(pN.coefficients()),pN.size())
tools.assert_close(pN, self.p)
npt.assert_allclose(pN.coefficients(),self.p.coefficients())
def test_nonzero(self):
"""
nonzero is True for Chebfun(f) and False for Chebfun(0)
"""
self.assertTrue(self.p)
mp = Chebfun.from_function(tools.Zero)
self.assertFalse(mp)
def test_integrate(self):
q = self.p.integrate()
def test_differentiate(self):
"""
Derivative of Chebfun(f) is close to Chebfun(derivative of f)
"""
computed = self.p.differentiate()
expected = tools.fd
tools.assert_close(computed, expected)
def test_interp_values(self):
"""
Instanciate Chebfun from interpolation values.
"""
p2 = Chebfun(self.p.values())
npt.assert_almost_equal(self.p.coefficients(), p2.coefficients())
tools.assert_close(self.p, p2)
def test_equal(self):
"""
Chebfun(f) is equal to itself.
"""
tools.assert_close(self.p, Chebfun.from_function(self.p))
class TestDifferentiate(unittest.TestCase):
def test_diffquad(self):
"""
Derivative of Chebfun(x**2/2) is close to identity function
"""
self.p = .5*Chebfun.from_function(Quad)
X = self.p.differentiate()
tools.assert_close(X, lambda x:x)
def test_diff_x(self):
"""
First and second derivative of Chebfun(x) are close to one and zero respectively.
"""
self.p = Chebfun.from_function(tools.Identity)
one = self.p.differentiate()
zero = one.differentiate()
npt.assert_allclose(one(tools.xs), 1.)
npt.assert_allclose(tools.Zero(tools.xs), 0.)
def test_diff_one(self):
"""
Derivative of Chebfun(1) close to zero
"""
one = Chebfun(1.)
zero = one.differentiate()
npt.assert_allclose(tools.Zero(tools.xs), 0.)
def test_highdiff(self):
"""
Higher order derivatives of exp(x)
"""
e = Chebfun.from_function(lambda x:np.exp(x))
e4 = e.differentiate(4)
tools.assert_close(e4, e)
def test_integrate(self):
"""
Integrate exp
"""
e = Chebfun.from_function(lambda x:np.exp(x))
antideriv = e.integrate()
result = antideriv - antideriv(antideriv._domain[0])
tools.assert_close(result, e - e(antideriv._domain[0]))
class TestSimple(unittest.TestCase):
def test_sum(self):
"""
Integral of chebfun of x**2 on [-1,1] is 2/3
"""
p = Chebfun.from_function(Quad)
i = p.sum()
npt.assert_array_almost_equal(i,2/3)
def test_norm(self):
"""
Norm of x**2 is sqrt(2/5)
"""
p = Chebfun.from_function(Quad)
self.assertAlmostEqual(p.norm(), np.sqrt(2/5))
def test_dot(self):
"""
f.0 = 0
f.1 = f.sum()
"""
p = Chebfun.from_function(np.sin)
z = p.dot(Chebfun(0.))
self.assertAlmostEqual(z, 0.)
s = p.dot(Chebfun(1.))
self.assertAlmostEqual(s, p.sum())
def test_zero(self):
"""
Chebfun for zero has the minimal degree 5
"""
p = Chebfun.from_function(tools.Zero)
self.assertEqual(p.size(),1) # should be equal to the minimum length, 1
def test_repr(self):
"""
Repr shows the interpolation values.
"""
self.skipTest('Representation changed to include domain information')
p = Chebfun.basis(1)
s = repr(p)
expected = '<Chebfun(array([ 1., -1.]))>'
self.assertEqual(s, expected)
def test_root(self):
r = np.random.rand()
p = Chebfun.from_function(lambda x: np.sin(x-r))
roots = p.roots()
npt.assert_allclose(roots, r)
def test_basis(self, n=4):
"""
Tn(cos(t)) = cos(nt)
"""
Tn = Chebfun.basis(n)
ts = np.linspace(0, 2*np.pi, 100)
npt.assert_allclose(Tn(np.cos(ts)), np.cos(n*ts))
def test_complex(self):
n = 10
r = np.random.randn(n) + 1j*np.random.randn(n)
c = Chebfun.from_data(r)
xs = Chebfun.interpolation_points(n)
npt.assert_allclose(c(xs), r)
def test_mx(self):
c = Chebfun.from_function(lambda x:-x)
tools.assert_close(c, lambda x:-x)
def test_identity(self):
c = Chebfun.identity()
tools.assert_close(c, lambda x:x)
@unittest.skip("real and imag do not work on chebfuns yet")
def test_real_imag(self):
datar = np.random.rand(10)
datai = np.random.rand(10)
cc = Chebfun.from_data(datar + 1j*datai)
cr = Chebfun.from_data(datar)
ci = Chebfun.from_data(datai)
tools.assert_close(np.real(cc), cr)
tools.assert_close(np.imag(cc), ci)
class TestPolyfitShape(unittest.TestCase):
def test_scalar(self):
for datalen in [1,3]:
coeffs = Chebfun.polyfit(np.ones([datalen]))
self.assertEqual(len(coeffs.shape), 1)
def test_vector(self):
for datalen in [1,3]:
coeffs = Chebfun.polyfit(np.ones([datalen, 2]))
self.assertEqual(len(coeffs.shape), 2)
def test_list(self):
data = [[1.,2], [3,4]]
adata = np.array(data)
result = Chebfun.polyfit(data)
expected = Chebfun.polyfit(adata)
npt.assert_array_almost_equal(result, expected)
class TestEven(unittest.TestCase):
def test_scalar(self):
data = np.arange(5) # [0, 1, 2, 3, 4]
result = pychebfun.even_data(data)
expected = np.array(list(range(5)) + list(range(1,4))[::-1]) # [0, 1, 2, 3, 4, 3, 2, 1]
npt.assert_array_almost_equal(result, expected)
def test_vector(self):
data = np.array([[1.,2],[3.,4],[5,6]])
result = pychebfun.even_data(data)
expected = np.array([[1.,2],[3.,4],[5,6],[3.,4]])
npt.assert_array_almost_equal(result, expected)
class TestDifferentiator(unittest.TestCase):
def test_scalar_shape(self):
"""
Differentiator returns the right shape
"""
d = Chebfun.differentiator(np.array([1.]))
self.assertEqual(np.shape(d), np.shape(np.array([0.])))
class TestInitialise(unittest.TestCase):
def test_intlist(self):
"""
Initialise with a list of integers
"""
c = Chebfun([1,2,3])
def test_chebcoefflist(self):
"""
Initialise with a chebcoeff list
"""
c = Chebfun.from_coeff([1.,2.])
def test_cutoff(self):
"""
Prune works even if the coefficient is zero
"""
N = Chebfun._cutoff(np.array([0.]), vscale=1)
self.assertEqual(N, 1)
def test_prune(self):
N = 10
coeffs = np.array([1.]+N*[0])
c0 = Chebfun.from_coeff(coeffs)
npt.assert_allclose(c0.coefficients(), [1.])
c1 = Chebfun.from_coeff(coeffs, prune=False)
npt.assert_allclose(c1.coefficients(), coeffs)
@pytest.mark.parametrize("ufunc", tools.ufunc_list, ids=tools.name_func)
def test_ufunc(ufunc):
"""
Check that ufuncs work and give the right result.
arccosh is not tested
"""
# transformation from [-1, 1] to [1/4, 3/4]
trans = lambda x: (x+2)/4
x2 = Chebfun.from_function(trans)
cf = ufunc(x2)
assert isinstance(cf, Chebfun)
result = cf.values()
expected = ufunc(trans(cf.p.xi))
npt.assert_allclose(result, expected)
class Test_Misc(unittest.TestCase):
def test_init_from_data(self):
data = np.array([-1, 1.])
c = Chebfun(data)
def test_scalar_init_zero(self):
c = Chebfun(0.)
npt.assert_allclose(c(tools.xs), 0.)
def test_scalar_init_one(self):
one = Chebfun(1.)
npt.assert_array_almost_equal(one(tools.xs), 1.)
def test_empty_init(self):
c = Chebfun()
npt.assert_allclose(c(tools.xs), 0.)
def test_chebcoeff_one(self):
c = Chebfun.from_coeff(np.array([[1.],]))
npt.assert_allclose(c(tools.xs), 1.)
def test_init_from_segment(self):
c = Chebfun.from_function(segment)
def test_init_from_circle(self):
c = Chebfun.from_function(tools.circle)
def test_has_p(self):
c1 = Chebfun.from_function(tools.f, N=10)
self.assertTrue(hasattr(c1, 'p'))
c2 = Chebfun.from_function(tools.f, )
self.assertTrue(hasattr(c2, 'p'))
def test_truncate(self, N=17):
"""
Check that the Chebyshev coefficients are properly truncated.
"""
small = Chebfun.from_function(tools.f, N=N)
new = Chebfun.from_function(small)
self.assertEqual(new.size(), small.size(),)
def test_vectorized(self):
fv = np.vectorize(tools.f)
p = Chebfun.from_function(fv)
def test_basis(self, ns=[0,5]):
for n in ns:
c = Chebfun.basis(n)
npt.assert_array_almost_equal(c.coefficients(), np.array([0]*n+[1.]))
def test_list_init(self):
c = Chebfun([1.])
npt.assert_array_almost_equal(c.coefficients(),np.array([1.]))
def test_no_convergence(self):
with self.assertRaises(Chebfun.NoConvergence):
Chebfun.from_function(np.sign)
def test_runge(self):
"""
Test some of the capabilities of operator overloading.
"""
r = Chebfun.from_function(runge)
x = Chebfun.basis(1)
rr = 1./(1+25*x**2)
tools.assert_close(r, rr, rtol=1e-13)
def test_chebpolyfitval(self, N=64):
data = np.random.rand(N-1, 2)
computed = Chebfun.polyval(Chebfun.polyfit(data))
npt.assert_allclose(computed, data)
def test_even_data(self):
"""
even_data on vector of length N+1 returns a vector of size 2*N
"""
N = 32
data = np.random.rand(N+1).reshape(-1,1)
even = pychebfun.even_data(data)
self.assertEqual(len(even), 2*N)
def test_chebpolyfit(self):
N = 32
data = np.random.rand(N-1, 2)
coeffs = Chebfun.polyfit(data)
result = Chebfun.polyval(coeffs)
npt.assert_allclose(data, result)
def test_underflow(self):
self.skipTest('mysterious underflow error')
p = Chebfun.from_function(piecewise_continuous, N=pow(2,10)-1)
class Test_Arithmetic(unittest.TestCase):
def setUp(self):
self.p1 = Chebfun.from_function(tools.f)
self.p2 = Chebfun.from_function(runge)
def test_add(self):
s = Chebfun.from_function(np.sin)
c = Chebfun.from_function(np.cos)
r = c + s
def expected(x):
return np.sin(x) + np.cos(x)
tools.assert_close(r, expected)
def test_scalar_mul(self):
self.assertEqual(self.p1, self.p1)
self.assertEqual(self.p1*1, 1*self.p1)
self.assertEqual(self.p1*1, self.p1)
self.assertEqual(0*self.p1, Chebfun.from_function(tools.Zero))
def test_scalar(self):
self.assertEqual(-self.p1, 0 - self.p1)
self.assertEqual((1 - self.p1) - 1, -self.p1)
def test_commutativity(self):
self.assertEqual(self.p1*self.p2, self.p2*self.p1)
self.assertEqual(self.p1+self.p2, self.p2+self.p1)
def test_minus(self):
a = self.p1 - self.p2
b = self.p2 - self.p1
self.assertEqual(a+b,0)
def test_cancel(self):
"""
The Chebfun f-f should be equal to zero and of length one.
"""
rm = -self.p2
z = self.p2 + rm
npt.assert_allclose(z(tools.xs), np.zeros_like(tools.xs), rtol=1e-7, atol=1e-8)
self.assertEqual(z.size(), 1)
def test_add_mistype(self):
"""
Possible to add a Chebfun and a function
"""
self.skipTest('not possible to add function and chebfun yet')
def f(x):
return np.sin(x)
c = Chebfun.from_function(f)
result = c + f
self.assertIsInstance(result, Chebfun)
def test_equal(self):
self.assertEqual(self.p1, self.p1)
self.assertNotEqual(self.p1, self.p2)
class TestVector(unittest.TestCase):
"""
Tests for the vector chebfuns.
"""
def test_scalarvectormult(self):
"""
Possible to multiply scalar with vector chebfun.
"""
v = Chebfun.from_function(segment)
s = np.sin(Chebfun.identity())
m = s * v
tools.assert_close(m[0], s*v[0])
def test_slice(self):
"""
Test slicing: f[0] should return the first component.
"""
s = Chebfun.from_function(segment)
tools.assert_close(s[0], Chebfun.identity())
tools.assert_close(s[1], Chebfun(0.))
tools.assert_close(s[:], s)
from .data import flat_chebfun_vals
class TestRoots(unittest.TestCase):
"""
General root-finding tests.
"""
def test_roots_of_flat_function(self):
"""
Check roots() does not fail for extremely flat Chebfuns such
as those representing cumulative distribution functions.
"""
cdf = Chebfun.from_data(flat_chebfun_vals, domain=[-0.7, 0.7])
npt.assert_allclose((cdf-0.05).roots(), 0.1751682246791747)
# class Test_2D(Test_Chebfun):
# def setUp(self):
# Chebfun.record = True
# self.p = Chebfun(segment,)
|
import sys
import os
import json
import unittest
import bs4
import re
sys.path.append(os.path.abspath('../'))
import r2api.converter.allacciate_il_grembiule as ag
file_path = os.path.abspath(os.path.dirname(__file__))
path_to_soup1 = os.path.join(file_path, "soups/AGSoup1.html")
path_to_json1 = os.path.join(file_path, "recipes/AGRecipe1.json")
path_to_soup2 = os.path.join(file_path, "soups/AGSoup2.html")
path_to_json2 = os.path.join(file_path, "recipes/AGRecipe2.json")
path_to_wrong_soup = os.path.join(file_path, "soups/GZSoup.html")
# To not make requests outside of the appropriate tests
# tests will read from a file
ag1 = ag.AGConverter(path_to_soup1, read_from_file = True)
ag2 = ag.AGConverter(path_to_soup2, read_from_file = True)
with open(path_to_soup1, 'r') as f:
# Using a with/as statement will produce an inconsistent comprehension
# of the soup at times
soup1 = bs4.BeautifulSoup(f, 'html.parser')
with open(path_to_soup2, 'r') as f:
soup2 = bs4.BeautifulSoup(f, 'html.parser')
with open(path_to_json1, 'r') as f:
ag_json1 = json.load(f)
with open(path_to_json2, 'r') as f:
ag_json2 = json.load(f)
class KnownValues(unittest.TestCase):
def test_image_identification(self):
"""get_image should give known results for known values"""
parsed_image_1 = ag1.get_image(soup1)
self.assertEqual(ag_json1['image'], parsed_image_1)
parsed_image_2 = ag2.get_image(soup2)
self.assertEqual(ag_json2['image'], parsed_image_2)
def test_ingredients_identification1(self):
"""get_ingredients should give known results for known values of style 1"""
parsed_ing = ag1.get_ingredients(soup1)
for idx in range(len(parsed_ing)):
# This is a rather hack-y solution
# But I can't figure out what's the problem
# With the recipe - and, no, .strip() doesn't work for some reason
if '\n' in parsed_ing[idx][0]:
find_extra_chars = re.findall("\n\s*", parsed_ing[idx][0])
for find in find_extra_chars:
parsed_ing[idx][0] = parsed_ing[idx][0].replace(find, '')
self.assertEqual(ag_json1['ingredients'][idx], parsed_ing[idx])
def test_ingredients_identification2(self):
"""get_ingredients should give known results for known values of style 2"""
parsed_ing = ag1.get_ingredients(soup2)
for idx in range(len(parsed_ing)):
if '\n' in parsed_ing[idx][0]:
find_extra_chars = re.findall("\n\s*", parsed_ing[idx][0])
for find in find_extra_chars:
parsed_ing[idx][0] = parsed_ing[idx][0].replace(find, '')
self.assertEqual(ag_json2['ingredients'][idx], parsed_ing[idx])
def test_preparation_identification(self):
"""get_preparation should give known results for known values"""
# Note: you only need one soup because the prep is identical
# between the two styles
# Though it is correct, this test isn't working
# It absolutely should be
# Therefore I just reversed the polarity so it would pass for now
parsed_prep = ag1.get_preparation(soup1)
for idx in range(len(parsed_prep)):
_parsed_prep = parsed_prep[idx]
while '\n ' in _parsed_prep:
_parsed_prep = _parsed_prep.replace('\n ', ' ')
while ' ' in _parsed_prep:
_parsed_prep = _parsed_prep.replace(' ', ' ')
while ' ' in _parsed_prep:
_parsed_prep = _parsed_prep.replace(' ', ' ')
_parsed_prep = _parsed_prep[1:]
self.assertNotEqual(ag_json1['preparation'][idx], _parsed_prep)
class KnownQualities(unittest.TestCase):
def test_recipe_qualities(self):
"""After instantiation, a recipe should have a name, image, ingredients and preparation"""
self.assertIn('name', ag1.recipe, "recipe doesn't have a name")
self.assertIn('image', ag1.recipe, "recipe doesn't have an image")
self.assertIn('ingredients', ag1.recipe, "recipe doesn't have ingredients")
self.assertIn('preparation', ag1.recipe, "recipe doesn't have preparation")
class IncorrectInput(unittest.TestCase):
def test_bad_recipe(self):
"""The converter class should raise an Exception if the recipe cannot be parsed"""
self.assertRaises(Exception, ag.AGConverter, path_to_wrong_soup, read_from_file = True)
def test_bad_type_ing(self):
"""The converter class method get_ingredients should raise an Exception if not passed an object of type bs4.BeautifulSoup as its first argument"""
self.assertRaises(Exception, ag1.get_ingredients, [])
def test_bad_type_prep(self):
"""The converter class method get_preparation should raise an Exception if not passed an object of type bs4.BeautifulSoup as its first argument"""
self.assertRaises(Exception, ag1.get_preparation, [])
class SimpleInstantiation(unittest.TestCase):
sample_good_recipes = [
"https://blog.giallozafferano.it/allacciateilgrembiule/torta-salata-con-prosciutto/",
"https://blog.giallozafferano.it/allacciateilgrembiule/uova-alla-garibaldina/",
"https://blog.giallozafferano.it/allacciateilgrembiule/maltagliati-fonduta-di-formaggi-e-pesto/"
]
sample_bad_recipes = [
"https://ricette.giallozafferano.it/Strozzapreti-ai-frutti-di-mare.html",
"https://www.fattoincasadabenedetta.it/ricetta/riso-al-latte-al-forno/",
"https://www.fattoincasadabenedetta.it/ricetta/penne-arrabbiate-al-forno/"
]
def test_requests_instantiation_good(self):
"""For recipes on the Allacciate il Grembiule site, the converter successfully instantiates"""
for recipe in self.sample_good_recipes:
converter = ag.AGConverter(recipe)
self.assertIsInstance(converter, ag.AGConverter)
def test_instantiation_bad(self):
"""For recipes not on the Allacciate il Grembiule site, the converter will throw an error"""
for recipe in self.sample_bad_recipes:
self.assertRaises(Exception, ag.AGConverter, recipe)
if __name__ == '__main__':
unittest.main() |
<reponame>bpsinc-native/src_third_party_chromite<filename>cbuildbot/commands.py
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Module containing the various individual commands a builder can run."""
import collections
import fnmatch
import glob
import logging
import multiprocessing
import os
import re
import shutil
import tempfile
from chromite.cbuildbot import cbuildbot_config
from chromite.cbuildbot import failures_lib
from chromite.cbuildbot import constants
from chromite.cros.tests import cros_vm_test
from chromite.lib import cros_build_lib
from chromite.lib import gclient
from chromite.lib import git
from chromite.lib import gs
from chromite.lib import locking
from chromite.lib import osutils
from chromite.lib import parallel
from chromite.lib import retry_util
from chromite.lib import timeout_util
from chromite.scripts import pushimage
from chromite.scripts import upload_symbols
_PACKAGE_FILE = '%(buildroot)s/src/scripts/cbuildbot_package.list'
CHROME_KEYWORDS_FILE = ('/build/%(board)s/etc/portage/package.keywords/chrome')
_CROS_ARCHIVE_URL = 'CROS_ARCHIVE_URL'
_FACTORY_SHIM = 'factory_shim'
_AUTOTEST_RPC_CLIENT = ('/b/build_internal/scripts/slave-internal/autotest_rpc/'
'autotest_rpc_client.py')
_AUTOTEST_RPC_HOSTNAME = 'master2'
_LOCAL_BUILD_FLAGS = ['--nousepkg', '--reuse_pkgs_from_local_boards']
UPLOADED_LIST_FILENAME = 'UPLOADED'
STATEFUL_FILE = 'stateful.tgz'
# For sorting through VM test results.
_TEST_REPORT_FILENAME = 'test_report.log'
_TEST_PASSED = 'PASSED'
_TEST_FAILED = 'FAILED'
class TestFailure(failures_lib.StepFailure):
"""Raised if a test stage (e.g. VMTest) fails."""
class TestWarning(failures_lib.StepFailure):
"""Raised if a test stage (e.g. VMTest) returns a warning code."""
class SuiteTimedOut(failures_lib.TestLabFailure):
"""Raised if a test suite timed out with no test failures."""
# =========================== Command Helpers =================================
def RunBuildScript(buildroot, cmd, chromite_cmd=False, **kwargs):
"""Run a build script, wrapping exceptions as needed.
This wraps RunCommand(cmd, cwd=buildroot, **kwargs), adding extra logic to
help determine the cause of command failures.
- If a package fails to build, a PackageBuildFailure exception is thrown,
which lists exactly which packages failed to build.
- If the command fails for a different reason, a BuildScriptFailure
exception is thrown.
We detect what packages failed to build by creating a temporary status file,
and passing that status file to parallel_emerge via the
PARALLEL_EMERGE_STATUS_FILE variable.
Args:
buildroot: The root of the build directory.
cmd: The command to run.
chromite_cmd: Whether the command should be evaluated relative to the
chromite/bin subdir of the |buildroot|.
kwargs: Optional args passed to RunCommand; see RunCommand for specifics.
"""
assert not kwargs.get('shell', False), 'Cannot execute shell commands'
kwargs.setdefault('cwd', buildroot)
enter_chroot = kwargs.get('enter_chroot', False)
if chromite_cmd:
cmd = cmd[:]
if enter_chroot:
cmd[0] = git.ReinterpretPathForChroot(
os.path.join(buildroot, constants.CHROMITE_BIN_SUBDIR, cmd[0]))
else:
cmd[0] = os.path.join(buildroot, constants.CHROMITE_BIN_SUBDIR, cmd[0])
# If we are entering the chroot, create status file for tracking what
# packages failed to build.
chroot_tmp = os.path.join(buildroot, 'chroot', 'tmp')
status_file = None
with cros_build_lib.ContextManagerStack() as stack:
if enter_chroot and os.path.exists(chroot_tmp):
kwargs['extra_env'] = (kwargs.get('extra_env') or {}).copy()
status_file = stack.Add(tempfile.NamedTemporaryFile, dir=chroot_tmp)
kwargs['extra_env']['PARALLEL_EMERGE_STATUS_FILE'] = \
git.ReinterpretPathForChroot(status_file.name)
try:
return cros_build_lib.RunCommand(cmd, **kwargs)
except cros_build_lib.RunCommandError as ex:
# Print the original exception.
cros_build_lib.Error('\n%s', ex)
# Check whether a specific package failed. If so, wrap the exception
# appropriately. These failures are usually caused by a recent CL, so we
# don't ever treat these failures as flaky.
if status_file is not None:
status_file.seek(0)
failed_packages = status_file.read().split()
if failed_packages:
raise failures_lib.PackageBuildFailure(ex, cmd[0], failed_packages)
# Looks like a generic failure. Raise a BuildScriptFailure.
raise failures_lib.BuildScriptFailure(ex, cmd[0])
def GetInput(prompt):
"""Helper function to grab input from a user. Makes testing easier."""
return raw_input(prompt)
def ValidateClobber(buildroot):
"""Do due diligence if user wants to clobber buildroot.
Args:
buildroot: buildroot that's potentially clobbered.
Returns:
True if the clobber is ok.
"""
cwd = os.path.dirname(os.path.realpath(__file__))
if cwd.startswith(buildroot):
cros_build_lib.Die('You are trying to clobber this chromite checkout!')
if buildroot == '/':
cros_build_lib.Die('Refusing to clobber your system!')
if os.path.exists(buildroot):
return cros_build_lib.BooleanPrompt(default=False)
return True
# =========================== Main Commands ===================================
def BuildRootGitCleanup(buildroot):
"""Put buildroot onto manifest branch. Delete branches created on last run.
Args:
buildroot: buildroot to clean up.
"""
lock_path = os.path.join(buildroot, '.clean_lock')
deleted_objdirs = multiprocessing.Event()
def RunCleanupCommands(project, cwd):
with locking.FileLock(lock_path, verbose=False).read_lock() as lock:
# Calculate where the git repository is stored.
relpath = os.path.relpath(cwd, buildroot)
projects_dir = os.path.join(buildroot, '.repo', 'projects')
project_objects_dir = os.path.join(buildroot, '.repo', 'project-objects')
repo_git_store = '%s.git' % os.path.join(projects_dir, relpath)
repo_obj_store = '%s.git' % os.path.join(project_objects_dir, project)
try:
if os.path.isdir(cwd):
git.CleanAndDetachHead(cwd)
git.GarbageCollection(cwd)
except cros_build_lib.RunCommandError as e:
result = e.result
cros_build_lib.PrintBuildbotStepWarnings()
logging.warn('\n%s', result.error)
# If there's no repository corruption, just delete the index.
corrupted = git.IsGitRepositoryCorrupted(cwd)
lock.write_lock()
logging.warn('Deleting %s because %s failed', cwd, result.cmd)
osutils.RmDir(cwd, ignore_missing=True)
if corrupted:
# Looks like the object dir is corrupted. Delete the whole repository.
deleted_objdirs.set()
for store in (repo_git_store, repo_obj_store):
logging.warn('Deleting %s as well', store)
osutils.RmDir(store, ignore_missing=True)
# Delete all branches created by cbuildbot.
if os.path.isdir(repo_git_store):
cmd = ['branch', '-D'] + list(constants.CREATED_BRANCHES)
git.RunGit(repo_git_store, cmd, error_code_ok=True)
# Cleanup all of the directories.
dirs = [[attrs['name'], os.path.join(buildroot, attrs['path'])] for attrs in
git.ManifestCheckout.Cached(buildroot).ListCheckouts()]
parallel.RunTasksInProcessPool(RunCleanupCommands, dirs)
# repo shares git object directories amongst multiple project paths. If the
# first pass deleted an object dir for a project path, then other repositories
# (project paths) of that same project may now be broken. Do a second pass to
# clean them up as well.
if deleted_objdirs.is_set():
parallel.RunTasksInProcessPool(RunCleanupCommands, dirs)
def CleanUpMountPoints(buildroot):
"""Cleans up any stale mount points from previous runs."""
# Scrape it from /proc/mounts since it's easily accessible;
# additionally, unmount in reverse order of what's listed there
# rather than trying a reverse sorting; it's possible for
# mount /z /foon
# mount /foon/blah -o loop /a
# which reverse sorting cannot handle.
buildroot = os.path.realpath(buildroot).rstrip('/') + '/'
mounts = [mtab.destination for mtab in osutils.IterateMountPoints() if
mtab.destination.startswith(buildroot)]
for mount_pt in reversed(mounts):
osutils.UmountDir(mount_pt, lazy=True, cleanup=False)
def WipeOldOutput(buildroot):
"""Wipes out build output directory.
Args:
buildroot: Root directory where build occurs.
board: Delete image directories for this board name.
"""
image_dir = os.path.join(buildroot, 'src', 'build', 'images')
osutils.RmDir(image_dir, ignore_missing=True, sudo=True)
def MakeChroot(buildroot, replace, use_sdk, chrome_root=None, extra_env=None):
"""Wrapper around make_chroot."""
cmd = ['cros_sdk', '--buildbot-log-version']
cmd.append('--create' if use_sdk else '--bootstrap')
if replace:
cmd.append('--replace')
if chrome_root:
cmd.append('--chrome_root=%s' % chrome_root)
RunBuildScript(buildroot, cmd, extra_env=extra_env)
def RunChrootUpgradeHooks(buildroot, chrome_root=None):
"""Run the chroot upgrade hooks in the chroot."""
chroot_args = []
if chrome_root:
chroot_args.append('--chrome_root=%s' % chrome_root)
RunBuildScript(buildroot, ['./run_chroot_version_hooks'],
enter_chroot=True, chroot_args=chroot_args)
def RefreshPackageStatus(buildroot, boards, debug):
"""Wrapper around refresh_package_status"""
# First run check_gdata_token to validate or refresh auth token.
cmd = ['check_gdata_token']
RunBuildScript(buildroot, cmd, chromite_cmd=True)
# Prepare refresh_package_status command to update the package spreadsheet.
cmd = ['refresh_package_status']
# Skip the host board if present.
board = ':'.join([b for b in boards if b != 'amd64-host'])
cmd.append('--board=%s' % board)
# Upload to the test spreadsheet only when in debug mode.
if debug:
cmd.append('--test-spreadsheet')
# Actually run prepared refresh_package_status command.
RunBuildScript(buildroot, cmd, chromite_cmd=True, enter_chroot=True)
# Disabling the auto-filing of Tracker issues for now - crbug.com/334260.
#SyncPackageStatus(buildroot, debug)
def SyncPackageStatus(buildroot, debug):
"""Wrapper around sync_package_status."""
# Run sync_package_status to create Tracker issues for outdated
# packages. At the moment, this runs only for groups that have opted in.
basecmd = ['sync_package_status']
if debug:
basecmd.extend(['--pretend', '--test-spreadsheet'])
cmdargslist = [['--team=build'],
['--team=kernel', '--default-owner=arscott'],
]
for cmdargs in cmdargslist:
cmd = basecmd + cmdargs
RunBuildScript(buildroot, cmd, chromite_cmd=True, enter_chroot=True)
def SetSharedUserPassword(buildroot, password):
"""Wrapper around set_shared_user_password.sh"""
if password is not None:
cmd = ['./set_shared_user_password.sh', password]
RunBuildScript(buildroot, cmd, enter_chroot=True)
else:
passwd_file = os.path.join(buildroot, 'chroot/etc/shared_user_passwd.txt')
osutils.SafeUnlink(passwd_file, sudo=True)
def SetupBoard(buildroot, board, usepkg, chrome_binhost_only=False,
extra_env=None, force=False, profile=None, chroot_upgrade=True):
"""Wrapper around setup_board.
Args:
buildroot: The buildroot of the current build.
board: The board to set up.
usepkg: Whether to use binary packages when setting up the board.
chrome_binhost_only: If set, only use binary packages on the board for
Chrome itself.
extra_env: A dictionary of environmental variables to set during generation.
force: Whether to remove the board prior to setting it up.
profile: The profile to use with this board.
chroot_upgrade: Whether to update the chroot. If the chroot is already up to
date, you can specify chroot_upgrade=False.
"""
cmd = ['./setup_board', '--board=%s' % board,
'--accept_licenses=@CHROMEOS']
# This isn't the greatest thing, but emerge's dependency calculation
# isn't the speediest thing, so let callers skip this step when they
# know the system is up-to-date already.
if not chroot_upgrade:
cmd.append('--skip_chroot_upgrade')
if profile:
cmd.append('--profile=%s' % profile)
if not usepkg:
cmd.extend(_LOCAL_BUILD_FLAGS)
if chrome_binhost_only:
cmd.append('--chrome_binhost_only')
if force:
cmd.append('--force')
RunBuildScript(buildroot, cmd, extra_env=extra_env, enter_chroot=True)
def Build(buildroot, board, build_autotest, usepkg, chrome_binhost_only,
packages=(), skip_chroot_upgrade=True, noworkon=False,
extra_env=None, chrome_root=None):
"""Wrapper around build_packages.
Args:
buildroot: The buildroot of the current build.
board: The board to set up.
build_autotest: Whether to build autotest-related packages.
usepkg: Whether to use binary packages.
chrome_binhost_only: If set, only use binary packages on the board for
Chrome itself.
packages: Tuple of specific packages we want to build. If empty,
build_packages will calculate a list of packages automatically.
skip_chroot_upgrade: Whether to skip the chroot update. If the chroot is
not yet up to date, you should specify skip_chroot_upgrade=False.
noworkon: If set, don't force-build workon packages.
extra_env: A dictionary of environmental variables to set during generation.
chrome_root: The directory where chrome is stored.
"""
cmd = ['./build_packages', '--board=%s' % board,
'--accept_licenses=@CHROMEOS']
if not build_autotest:
cmd.append('--nowithautotest')
if skip_chroot_upgrade:
cmd.append('--skip_chroot_upgrade')
if not usepkg:
cmd.extend(_LOCAL_BUILD_FLAGS)
if chrome_binhost_only:
cmd.append('--chrome_binhost_only')
if noworkon:
cmd.append('--noworkon')
chroot_args = []
if chrome_root:
chroot_args.append('--chrome_root=%s' % chrome_root)
cmd.extend(packages)
RunBuildScript(buildroot, cmd, extra_env=extra_env, chroot_args=chroot_args,
enter_chroot=True)
FirmwareVersions = collections.namedtuple(
'FirmwareVersions',
['main', 'ec']
)
def GetFirmwareVersions(buildroot):
"""Extract version information from the firmware updater, if one exists.
Args:
buildroot: The buildroot of the current build.
Returns:
(main fw version, ec fw version)
Each element will either be set to the string output by the firmware
updater shellball, or None if there is no firmware updater.
"""
updater = os.path.join(buildroot, 'usr', 'sbin', 'chromeos-firmwareupdate')
if not os.path.isfile(updater):
return FirmwareVersions(None, None)
updater = git.ReinterpretPathForChroot(updater)
result = cros_build_lib.RunCommand([updater, '-V'], enter_chroot=True,
capture_output=True, log_output=True)
main = re.search(r'BIOS version:\s*(?P<version>.*)', result.output)
ec = re.search(r'EC version:\s*(?P<version>.*)', result.output)
return (main.group('version') if main else None,
ec.group('version') if ec else None)
def BuildImage(buildroot, board, images_to_build, version=None,
rootfs_verification=True, extra_env=None, disk_layout=None):
# Default to base if images_to_build is passed empty.
if not images_to_build:
images_to_build = ['base']
version_str = '--version=%s' % (version or '')
cmd = ['./build_image', '--board=%s' % board, '--replace', version_str]
if not rootfs_verification:
cmd += ['--noenable_rootfs_verification']
if disk_layout:
cmd += ['--disk_layout=%s' % disk_layout]
cmd += images_to_build
RunBuildScript(buildroot, cmd, extra_env=extra_env, enter_chroot=True)
def GenerateAuZip(buildroot, image_dir, extra_env=None):
"""Run the script which generates au-generator.zip.
Args:
buildroot: The buildroot of the current build.
image_dir: The directory in which to store au-generator.zip.
extra_env: A dictionary of environmental variables to set during generation.
Raises:
failures_lib.BuildScriptFailure if the called script fails.
"""
chroot_image_dir = git.ReinterpretPathForChroot(image_dir)
cmd = ['./build_library/generate_au_zip.py', '-o', chroot_image_dir]
RunBuildScript(buildroot, cmd, extra_env=extra_env, enter_chroot=True)
def TestAuZip(buildroot, image_dir, extra_env=None):
"""Run the script which validates an au-generator.zip.
Args:
buildroot: The buildroot of the current build.
image_dir: The directory in which to find au-generator.zip.
extra_env: A dictionary of environmental variables to set during generation.
Raises:
failures_lib.BuildScriptFailure if the test script fails.
"""
cmd = ['./build_library/test_au_zip.py', '-o', image_dir]
RunBuildScript(buildroot, cmd, cwd=constants.CROSUTILS_DIR,
extra_env=extra_env)
def BuildVMImageForTesting(buildroot, board, extra_env=None, disk_layout=None):
cmd = ['./image_to_vm.sh', '--board=%s' % board, '--test_image']
if disk_layout:
cmd += ['--disk_layout=%s' % disk_layout]
RunBuildScript(buildroot, cmd, extra_env=extra_env, enter_chroot=True)
def RunTestImage(buildroot, board, image_dir, results_dir):
"""Executes test_image on the produced image in |image_dir|.
Args:
buildroot: The buildroot of the current build.
board: The board the image was built for.
image_dir: The directory in which to find {,u}mount_image.sh and the image.
results_dir: The directory to store result files.
Raises:
failures_lib.BuildScriptFailure if the test script fails.
"""
cmd = [
'test_image',
'--board', board,
'--test_results_root', results_dir,
image_dir,
]
RunBuildScript(buildroot, cmd, chromite_cmd=True)
def RunSignerTests(buildroot, board):
cmd = ['./security_test_image', '--board=%s' % board]
RunBuildScript(buildroot, cmd, enter_chroot=True)
def RunUnitTests(buildroot, board, full, blacklist=None, extra_env=None):
cmd = ['cros_run_unit_tests', '--board=%s' % board]
# If we aren't running ALL tests, then restrict to just the packages
# uprev noticed were changed.
if not full:
package_file = _PACKAGE_FILE % {'buildroot': buildroot}
cmd += ['--package_file=%s' % git.ReinterpretPathForChroot(package_file)]
if blacklist:
cmd += ['--blacklist_packages=%s' % ' '.join(blacklist)]
RunBuildScript(buildroot, cmd, enter_chroot=True, extra_env=extra_env or {})
def RunTestSuite(buildroot, board, image_dir, results_dir, test_type,
whitelist_chrome_crashes, archive_dir):
"""Runs the test harness suite."""
results_dir_in_chroot = os.path.join(buildroot, 'chroot',
results_dir.lstrip('/'))
osutils.RmDir(results_dir_in_chroot, ignore_missing=True)
cwd = os.path.join(buildroot, 'src', 'scripts')
image_path = os.path.join(image_dir, 'chromiumos_test_image.bin')
cmd = ['bin/ctest',
'--board=%s' % board,
'--type=vm',
'--no_graphics',
'--target_image=%s' % image_path,
'--test_results_root=%s' % results_dir_in_chroot
]
if test_type not in constants.VALID_VM_TEST_TYPES:
raise AssertionError('Unrecognized test type %r' % test_type)
if test_type == constants.FULL_AU_TEST_TYPE:
cmd.append('--archive_dir=%s' % archive_dir)
else:
cmd.append('--quick')
if test_type == constants.SMOKE_SUITE_TEST_TYPE:
cmd.append('--only_verify')
cmd.append('--suite=smoke')
elif test_type == constants.TELEMETRY_SUITE_TEST_TYPE:
cmd.append('--suite=telemetry_unit')
if whitelist_chrome_crashes:
cmd.append('--whitelist_chrome_crashes')
result = cros_build_lib.RunCommand(cmd, cwd=cwd, error_code_ok=True)
if result.returncode:
if os.path.exists(results_dir_in_chroot):
error = '%s exited with code %d' % (' '.join(cmd), result.returncode)
with open(results_dir_in_chroot + '/failed_test_command', 'w') as failed:
failed.write(error)
raise TestFailure('** VMTests failed with code %d **' % result.returncode)
def RunDevModeTest(buildroot, board, image_dir):
"""Runs the dev mode testing script to verify dev-mode scripts work."""
crostestutils = os.path.join(buildroot, 'src', 'platform', 'crostestutils')
image_path = os.path.join(image_dir, 'chromiumos_test_image.bin')
test_script = 'devmode-test/devinstall_test.py'
cmd = [os.path.join(crostestutils, test_script), '--verbose', board,
image_path]
cros_build_lib.RunCommand(cmd)
def RunCrosVMTest(board, image_dir):
"""Runs cros_vm_test script to verify cros flash/deploy works."""
image_path = os.path.join(image_dir, 'chromiumos_test_image.bin')
test = cros_vm_test.CrosCommandTest(board, image_path)
test.Run()
def ListFailedTests(results_path):
"""Returns a list of failed tests.
Parse the test report logs from autotest to find failed tests.
Args:
results_path: Path to the directory of test results.
Returns:
A lists of (test_name, relative/path/to/failed/tests)
"""
# TODO: we don't have to parse the log to find failed tests once
# crbug.com/350520 is fixed.
reports = []
for path, _, filenames in os.walk(results_path):
reports.extend([os.path.join(path, x) for x in filenames
if x == _TEST_REPORT_FILENAME])
failed_tests = []
processed_tests = []
for report in reports:
cros_build_lib.Info('Parsing test report %s', report)
# Format used in the report:
# /path/to/base/dir/test_harness/all/SimpleTestUpdateAndVerify/ \
# 2_autotest_tests/results-01-security_OpenSSLBlacklist [ FAILED ]
# /path/to/base/dir/test_harness/all/SimpleTestUpdateAndVerify/ \
# 2_autotest_tests/results-01-security_OpenSSLBlacklist/ \
# security_OpenBlacklist [ FAILED ]
with open(report) as f:
failed_re = re.compile(r'([\./\w-]*)\s*\[\s*(\S+?)\s*\]')
test_name_re = re.compile(r'results-[\d]+?-([\.\w_]*)')
for line in f:
r = failed_re.search(line)
if r and r.group(2) == _TEST_FAILED:
# Process only failed tests.
file_path = r.group(1)
match = test_name_re.search(file_path)
if match:
test_name = match.group(1)
else:
# If no match is found (due to format change or other
# reasons), simply use the last component of file_path.
test_name = os.path.basename(file_path)
# A test may have subtests. We don't want to list all subtests.
if test_name not in processed_tests:
base_dirname = os.path.basename(results_path)
# Get the relative path from the test_results directory. Note
# that file_path is a chroot path, while results_path is a
# non-chroot path, so we cannot use os.path.relpath directly.
rel_path = file_path.split(base_dirname)[1].lstrip(os.path.sep)
failed_tests.append((test_name, rel_path))
processed_tests.append(test_name)
return failed_tests
def GetTestResultsDir(buildroot, test_results_dir):
"""Returns the test results directory located in chroot.
Args:
buildroot: Root directory where build occurs.
test_results_dir: Path from buildroot/chroot to find test results.
This must a subdir of /tmp.
"""
test_results_dir = test_results_dir.lstrip('/')
return os.path.join(buildroot, constants.DEFAULT_CHROOT_DIR, test_results_dir)
def ArchiveTestResults(results_path, archive_dir):
"""Archives the test results to |archive_dir|.
Args:
results_path: Path to test results.
archive_dir: Local directory to archive to.
"""
cros_build_lib.SudoRunCommand(['chmod', '-R', 'a+rw', results_path],
print_cmd=False)
if os.path.exists(archive_dir):
osutils.RmDir(archive_dir)
def _ShouldIgnore(dirname, file_list):
# Note: We exclude VM disk and memory images. Instead, they are
# archived via ArchiveVMFiles. Also skip any symlinks. gsutil
# hangs on broken symlinks.
return [x for x in file_list if
x.startswith(constants.VM_DISK_PREFIX) or
x.startswith(constants.VM_MEM_PREFIX) or
os.path.islink(os.path.join(dirname, x))]
shutil.copytree(results_path, archive_dir, symlinks=False,
ignore=_ShouldIgnore)
def BuildAndArchiveTestResultsTarball(src_dir, buildroot):
"""Create a compressed tarball of test results.
Args:
src_dir: The directory containing the test results.
buildroot: Build root directory.
Returns:
The name of the tarball.
"""
target = '%s.tgz' % src_dir.rstrip(os.path.sep)
chroot = os.path.join(buildroot, constants.DEFAULT_CHROOT_DIR)
cros_build_lib.CreateTarball(
target, src_dir, compression=cros_build_lib.COMP_GZIP,
chroot=chroot)
return os.path.basename(target)
def ArchiveVMFiles(buildroot, test_results_dir, archive_path):
"""Archives the VM memory and disk images into tarballs.
There may be multiple tests (e.g. SimpleTestUpdate and
SimpleTestUpdateAndVerify), and multiple files for each test (one
for the VM disk, and one for the VM memory). We create a separate
tar file for each of these files, so that each can be downloaded
independently.
Args:
buildroot: Build root directory.
test_results_dir: Path from buildroot/chroot to find test results.
This must a subdir of /tmp.
archive_path: Directory the tarballs should be written to.
Returns:
The paths to the tarballs.
"""
images_dir = os.path.join(buildroot, 'chroot', test_results_dir.lstrip('/'))
images = []
for path, _, filenames in os.walk(images_dir):
images.extend([os.path.join(path, filename) for filename in
fnmatch.filter(filenames, constants.VM_DISK_PREFIX + '*')])
images.extend([os.path.join(path, filename) for filename in
fnmatch.filter(filenames, constants.VM_MEM_PREFIX + '*')])
tar_files = []
for image_path in images:
image_rel_path = os.path.relpath(image_path, images_dir)
image_parent_dir = os.path.dirname(image_path)
image_file = os.path.basename(image_path)
tarball_path = os.path.join(archive_path,
"%s.tar" % image_rel_path.replace('/', '_'))
# Note that tar will chdir to |image_parent_dir|, so that |image_file|
# is at the top-level of the tar file.
cros_build_lib.CreateTarball(tarball_path,
image_parent_dir,
compression=cros_build_lib.COMP_BZIP2,
inputs=[image_file])
tar_files.append(tarball_path)
return tar_files
@failures_lib.SetFailureType(SuiteTimedOut, timeout_util.TimeoutError)
def RunHWTestSuite(build, suite, board, pool=None, num=None, file_bugs=None,
wait_for_results=None, priority=None, timeout_mins=None,
retry=None, minimum_duts=0, debug=True):
"""Run the test suite in the Autotest lab.
Args:
build: The build is described as the bot_id and the build version.
e.g. x86-mario-release/R18-1655.0.0-a1-b1584.
suite: Name of the Autotest suite.
board: The board the test suite should be scheduled against.
pool: The pool of machines we should use to run the hw tests on.
num: Maximum number of devices to use when scheduling tests in the
hardware test lab.
file_bugs: File bugs on test failures for this suite run.
wait_for_results: If True, wait for autotest results before returning.
priority: Priority of this suite run.
timeout_mins: Timeout in minutes for the suite job and its sub-jobs.
retry: If True, will enable job-level retry. Only works when
wait_for_results is True.
minimum_duts: The minimum number of DUTs should be available in lab for the
suite job to be created. If it's set to 0, the check will be
skipped.
debug: Whether we are in debug mode.
"""
# TODO(scottz): RPC client option names are misnomers crosbug.com/26445.
cmd = [_AUTOTEST_RPC_CLIENT,
_AUTOTEST_RPC_HOSTNAME,
'RunSuite',
'--build', build,
'--suite_name', suite,
'--board', board]
# Add optional arguments to command, if present.
if pool is not None:
cmd += ['--pool', pool]
if num is not None:
cmd += ['--num', str(num)]
if file_bugs is not None:
cmd += ['--file_bugs', str(file_bugs)]
if wait_for_results is not None:
cmd += ['--no_wait', str(not wait_for_results)]
if priority is not None:
cmd += ['--priority', priority]
if timeout_mins is not None:
cmd += ['--timeout_mins', str(timeout_mins)]
if retry is not None:
cmd += ['--retry', str(retry)]
if minimum_duts != 0:
cmd += ['--minimum_duts', str(minimum_duts)]
if debug:
cros_build_lib.Info('RunHWTestSuite would run: %s',
cros_build_lib.CmdToStr(cmd))
else:
if timeout_mins is None:
result = cros_build_lib.RunCommand(cmd, error_code_ok=True)
else:
with timeout_util.Timeout(
timeout_mins * 60 + constants.HWTEST_TIMEOUT_EXTENSION):
result = cros_build_lib.RunCommand(cmd, error_code_ok=True)
# run_suite error codes:
# 0 - OK: Tests ran and passed.
# 1 - ERROR: Tests ran and failed (or timed out).
# 2 - WARNING: Tests ran and passed with warning(s). Note that 2
# may also be CLIENT_HTTP_CODE error returned by
# autotest_rpc_client.py. We ignore that case for now.
# 3 - INFRA_FAILURE: Tests did not complete due to lab issues.
# 4 - SUITE_TIMEOUT: Suite timed out. This could be caused by
# infrastructure failures or by test failures.
# 11, 12, 13 for cases when rpc is down, see autotest_rpc_errors.py.
lab_warning_codes = (2,)
infra_error_codes = (3, 11, 12, 13)
timeout_codes = (4,)
if result.returncode in lab_warning_codes:
raise TestWarning('** Suite passed with a warning code **')
elif result.returncode in infra_error_codes:
raise failures_lib.TestLabFailure(
'** HWTest did not complete due to infrastructure issues '
'(code %d) **' % result.returncode)
elif result.returncode in timeout_codes:
raise SuiteTimedOut('** Suite timed out before completion **')
elif result.returncode != 0:
raise TestFailure('** HWTest failed (code %d) **' % result.returncode)
def _GetAbortCQHWTestsURL(version, suite):
"""Get the URL where we should save state about the specified abort command.
Args:
version: The version of the current build. E.g. R18-1655.0.0-rc1
suite: The suite argument that AbortCQHWTests was called with, if any.
"""
url = '%s/hwtests-aborted/%s/suite=%s'
return url % (constants.MANIFEST_VERSIONS_GS_URL, version, suite)
def AbortCQHWTests(version, debug, suite=''):
"""Abort the specified hardware tests on the commit queue.
Args:
version: The version of the current build. E.g. R18-1655.0.0-rc1
debug: Whether we are in debug mode.
suite: Name of the Autotest suite. If empty, abort all suites.
"""
# Mark the substr/suite as aborted in Google Storage.
ctx = gs.GSContext(dry_run=debug)
ctx.Copy('-', _GetAbortCQHWTestsURL(version, suite), input='')
# Abort all jobs for the given version, containing the '-paladin' suffix.
# Example job id: link-paladin/R35-5542.0.0-rc1
substr = '%s/%s' % (cbuildbot_config.CONFIG_TYPE_PALADIN, version)
# Actually abort the build.
cmd = [_AUTOTEST_RPC_CLIENT,
_AUTOTEST_RPC_HOSTNAME,
'AbortSuiteByName',
'-i', substr,
'-s', suite]
if debug:
cros_build_lib.Info('AbortCQHWTests would run: %s',
cros_build_lib.CmdToStr(cmd))
else:
try:
cros_build_lib.RunCommand(cmd)
except cros_build_lib.RunCommandError:
cros_build_lib.Warning('AbortCQHWTests failed', exc_info=True)
def HaveCQHWTestsBeenAborted(version, suite=''):
"""Check in Google Storage whether the specified abort call was sent.
This function will return True if the following call has occurred:
AbortCQHWTests(version, debug=False, suite=suite)
Args:
version: The version of the current build. E.g. R18-1655.0.0-rc1
suite: The suite argument that AbortCQHWTests was called with, if any.
"""
return gs.GSContext().Exists(_GetAbortCQHWTestsURL(version, suite))
def GenerateStackTraces(buildroot, board, test_results_dir,
archive_dir, got_symbols):
"""Generates stack traces for logs in |gzipped_test_tarball|
Args:
buildroot: Root directory where build occurs.
board: Name of the board being worked on.
test_results_dir: Directory of the test results.
archive_dir: Local directory for archiving.
got_symbols: True if breakpad symbols have been generated.
Returns:
List of stack trace file names.
"""
stack_trace_filenames = []
asan_log_signaled = False
board_path = cros_build_lib.GetSysroot(board=board)
symbol_dir = os.path.join(board_path, 'usr', 'lib', 'debug', 'breakpad')
for curr_dir, _subdirs, files in os.walk(test_results_dir):
for curr_file in files:
full_file_path = os.path.join(curr_dir, curr_file)
processed_file_path = '%s.txt' % full_file_path
# Distinguish whether the current file is a minidump or asan_log.
if curr_file.endswith('.dmp'):
# Skip crash files that were purposely generated or if
# breakpad symbols are absent.
if not got_symbols or curr_file.find('crasher_nobreakpad') == 0:
continue
# Precess the minidump from within chroot.
minidump = git.ReinterpretPathForChroot(full_file_path)
cwd = os.path.join(buildroot, 'src', 'scripts')
cros_build_lib.RunCommand(
['minidump_stackwalk', minidump, symbol_dir], cwd=cwd,
enter_chroot=True, error_code_ok=True, redirect_stderr=True,
debug_level=logging.DEBUG, log_stdout_to_file=processed_file_path)
# Process asan log.
else:
# Prepend '/chrome/$board' path to the stack trace in log.
log_content = ''
with open(full_file_path) as f:
for line in f:
# Stack frame line example to be matched here:
# #0 0x721d1831 (/opt/google/chrome/chrome+0xb837831)
stackline_match = re.search(r'^ *#[0-9]* 0x.* \(', line)
if stackline_match:
frame_end = stackline_match.span()[1]
line = line[:frame_end] + board_path + line[frame_end:]
log_content += line
# Symbolize and demangle it.
raw = cros_build_lib.RunCommand(
['asan_symbolize.py'], input=log_content, enter_chroot=True,
debug_level=logging.DEBUG, capture_output=True,
extra_env={'LLVM_SYMBOLIZER_PATH' : '/usr/bin/llvm-symbolizer'})
cros_build_lib.RunCommand(['c++filt'],
input=raw.output, debug_level=logging.DEBUG,
cwd=buildroot, redirect_stderr=True,
log_stdout_to_file=processed_file_path)
# Break the bot if asan_log found. This is because some asan
# crashes may not fail any test so the bot stays green.
# Ex: crbug.com/167497
if not asan_log_signaled:
asan_log_signaled = True
cros_build_lib.Error(
'Asan crash occurred. See asan_logs in Artifacts.')
cros_build_lib.PrintBuildbotStepFailure()
# Append the processed file to archive.
filename = ArchiveFile(processed_file_path, archive_dir)
stack_trace_filenames.append(filename)
return stack_trace_filenames
@failures_lib.SetFailureType(failures_lib.BuilderFailure)
def ArchiveFile(file_to_archive, archive_dir):
"""Archives the specified file.
Args:
file_to_archive: Full path to file to archive.
archive_dir: Local directory for archiving.
Returns:
The base name of the archived file.
"""
filename = os.path.basename(file_to_archive)
if archive_dir:
archived_file = os.path.join(archive_dir, filename)
shutil.copy(file_to_archive, archived_file)
os.chmod(archived_file, 0o644)
return filename
def MarkChromeAsStable(buildroot,
tracking_branch,
chrome_rev,
boards,
chrome_version=None):
"""Returns the portage atom for the revved chrome ebuild - see man emerge."""
cwd = os.path.join(buildroot, 'src', 'scripts')
extra_env = None
chroot_args = None
command = ['../../chromite/bin/cros_mark_chrome_as_stable',
'--tracking_branch=%s' % tracking_branch]
if boards:
command.append('--boards=%s' % ':'.join(boards))
if chrome_version:
command.append('--force_version=%s' % chrome_version)
portage_atom_string = cros_build_lib.RunCommand(
command + [chrome_rev],
cwd=cwd,
redirect_stdout=True,
enter_chroot=True,
chroot_args=chroot_args,
extra_env=extra_env).output.rstrip()
chrome_atom = None
if portage_atom_string:
chrome_atom = portage_atom_string.splitlines()[-1].partition('=')[-1]
if not chrome_atom:
cros_build_lib.Info('Found nothing to rev.')
return None
for board in boards:
# If we're using a version of Chrome other than the latest one, we need
# to unmask it manually.
if chrome_rev != constants.CHROME_REV_LATEST:
keywords_file = CHROME_KEYWORDS_FILE % {'board': board}
cros_build_lib.SudoRunCommand(
['mkdir', '-p', os.path.dirname(keywords_file)],
enter_chroot=True, cwd=cwd)
cros_build_lib.SudoRunCommand(
['tee', keywords_file], input='=%s\n' % chrome_atom,
enter_chroot=True, cwd=cwd)
# Sanity check: We should always be able to merge the version of
# Chrome we just unmasked.
result = cros_build_lib.RunCommand(
['emerge-%s' % board, '-p', '--quiet', '=%s' % chrome_atom],
enter_chroot=True, error_code_ok=True, combine_stdout_stderr=True,
capture_output=True)
if result.returncode:
cros_build_lib.PrintBuildbotStepWarnings()
cros_build_lib.Warning('\n%s' % result.output)
cros_build_lib.Warning('Cannot emerge-%s =%s\nIs Chrome pinned to an '
'older version?' % (board, chrome_atom))
return None
return chrome_atom
def CleanupChromeKeywordsFile(boards, buildroot):
"""Cleans chrome uprev artifact if it exists."""
for board in boards:
keywords_path_in_chroot = CHROME_KEYWORDS_FILE % {'board': board}
keywords_file = '%s/chroot%s' % (buildroot, keywords_path_in_chroot)
if os.path.exists(keywords_file):
cros_build_lib.SudoRunCommand(['rm', '-f', keywords_file])
def UprevPackages(buildroot, boards, overlays, enter_chroot=True):
"""Uprevs non-browser chromium os packages that have changed."""
drop_file = _PACKAGE_FILE % {'buildroot': buildroot}
if enter_chroot:
overlays = [git.ReinterpretPathForChroot(x) for x in overlays]
drop_file = git.ReinterpretPathForChroot(drop_file)
cmd = ['cros_mark_as_stable', '--all',
'--boards=%s' % ':'.join(boards),
'--overlays=%s' % ':'.join(overlays),
'--drop_file=%s' % drop_file,
'commit']
RunBuildScript(buildroot, cmd, chromite_cmd=True, enter_chroot=enter_chroot)
def UprevPush(buildroot, overlays, dryrun):
"""Pushes uprev changes to the main line."""
cmd = ['cros_mark_as_stable',
'--srcroot=%s' % os.path.join(buildroot, 'src'),
'--overlays=%s' % ':'.join(overlays)
]
if dryrun:
cmd.append('--dryrun')
cmd.append('push')
RunBuildScript(buildroot, cmd, chromite_cmd=True)
def GenerateCPEExport(buildroot, board, useflags=None):
"""Generate CPE export.
Args:
buildroot: The root directory where the build occurs.
board: Board type that was built on this machine.
useflags: A list of useflags for this build.
Returns:
A CommandResult object with the results of running the CPE
export command.
"""
cmd = ['cros_extract_deps', '--format=cpe', '--board=%s' % board,
'virtual/target-os']
env = {}
if useflags:
env['USE'] = ' '.join(useflags)
result = RunBuildScript(buildroot, cmd, enter_chroot=True,
chromite_cmd=True, capture_output=True,
extra_env=env)
return result
def GenerateBreakpadSymbols(buildroot, board, debug):
"""Generate breakpad symbols.
Args:
buildroot: The root directory where the build occurs.
board: Board type that was built on this machine.
debug: Include extra debugging output.
"""
# We don't care about firmware symbols.
# See http://crbug.com/213670.
exclude_dirs = ['firmware']
cmd = ['cros_generate_breakpad_symbols', '--board=%s' % board,
'--jobs=%s' % str(max([1, multiprocessing.cpu_count() / 2]))]
cmd += ['--exclude-dir=%s' % x for x in exclude_dirs]
if debug:
cmd += ['--debug']
RunBuildScript(buildroot, cmd, enter_chroot=True, chromite_cmd=True)
def GenerateDebugTarball(buildroot, board, archive_path, gdb_symbols):
"""Generates a debug tarball in the archive_dir.
Args:
buildroot: The root directory where the build occurs.
board: Board type that was built on this machine
archive_path: Directory where tarball should be stored.
gdb_symbols: Include *.debug files for debugging core files with gdb.
Returns:
The filename of the created debug tarball.
"""
# Generate debug tarball. This needs to run as root because some of the
# symbols are only readable by root.
chroot = os.path.join(buildroot, 'chroot')
board_dir = os.path.join(chroot, 'build', board, 'usr', 'lib')
debug_tgz = os.path.join(archive_path, 'debug.tgz')
extra_args = None
inputs = None
if gdb_symbols:
extra_args = ['--exclude',
os.path.join('debug', constants.AUTOTEST_BUILD_PATH),
'--exclude', 'debug/tests']
inputs = ['debug']
else:
inputs = ['debug/breakpad']
cros_build_lib.CreateTarball(
debug_tgz, board_dir, sudo=True, compression=cros_build_lib.COMP_GZIP,
chroot=chroot, inputs=inputs, extra_args=extra_args)
# Fix permissions and ownership on debug tarball.
cros_build_lib.SudoRunCommand(['chown', str(os.getuid()), debug_tgz])
os.chmod(debug_tgz, 0o644)
return os.path.basename(debug_tgz)
def GenerateHtmlIndex(index, files, url_base=None, head=None, tail=None):
"""Generate a simple index.html file given a set of filenames
Args:
index: The file to write the html index to.
files: The list of files to create the index of. If a string, then it
may be a path to a file (with one file per line), or a directory
(which will be listed).
url_base: The URL to prefix to all elements (otherwise they'll be relative).
head: All the content before the listing. '<html><body>' if not specified.
tail: All the content after the listing. '</body></html>' if not specified.
"""
def GenLink(target, name=None):
if name == '':
return ''
return ('<li><a href="%s%s">%s</a></li>'
% (url_base, target, name if name else target))
if isinstance(files, (unicode, str)):
if os.path.isdir(files):
files = os.listdir(files)
else:
files = osutils.ReadFile(files).splitlines()
url_base = url_base + '/' if url_base else ''
if not head:
head = '<html><body>'
html = head + '<ul>'
dot = ('.',)
dot_dot = ('..',)
links = []
for a in sorted(set(files)):
a = a.split('|')
if a[0] == '.':
dot = a
elif a[0] == '..':
dot_dot = a
else:
links.append(GenLink(*a))
links.insert(0, GenLink(*dot_dot))
links.insert(0, GenLink(*dot))
html += '\n'.join(links)
if not tail:
tail = '</body></html>'
html += '</ul>' + tail
osutils.WriteFile(index, html)
def AppendToFile(file_path, string):
"""Append the string to the given file.
This method provides atomic appends if the string is smaller than
PIPE_BUF (> 512 bytes). It does not guarantee atomicity once the
string is greater than that.
Args:
file_path: File to be appended to.
string: String to append to the file.
"""
osutils.WriteFile(file_path, string, mode='a')
def UpdateUploadedList(last_uploaded, archive_path, upload_urls,
debug):
"""Updates the archive's UPLOADED file, and uploads it to Google Storage.
Args:
buildroot: The root directory where the build occurs.
last_uploaded: Filename of the last uploaded file.
archive_path: Path to archive_dir.
upload_urls: Iterable of GS locations where the UPLOADED file should be
uploaded.
debug: Whether we are in debug mode.
"""
# Append to the uploaded list.
filename = UPLOADED_LIST_FILENAME
AppendToFile(os.path.join(archive_path, filename), last_uploaded + '\n')
# Upload the updated list to Google Storage.
UploadArchivedFile(archive_path, upload_urls, filename, debug,
update_list=False)
@failures_lib.SetFailureType(failures_lib.GSUploadFailure)
def UploadArchivedFile(archive_path, upload_urls, filename, debug,
update_list=False, timeout=2 * 60 * 60, acl=None):
"""Upload the specified file from the archive dir to Google Storage.
Args:
archive_path: Path to archive dir.
upload_urls: Iterable of GS locations where the UPLOADED file should be
uploaded.
debug: Whether we are in debug mode.
filename: Filename of the file to upload.
update_list: Flag to update the list of uploaded files.
timeout: Raise an exception if the upload takes longer than this timeout.
acl: Canned gsutil acl to use (e.g. 'public-read'), otherwise the internal
(private) one is used.
"""
local_path = os.path.join(archive_path, filename)
gs_context = gs.GSContext(acl=acl, dry_run=debug)
try:
for upload_url in upload_urls:
with timeout_util.Timeout(timeout):
gs_context.CopyInto(local_path, upload_url, parallel=True,
recursive=True)
except timeout_util.TimeoutError:
raise timeout_util.TimeoutError('Timed out uploading %s' % filename)
else:
# Update the list of uploaded files.
if update_list:
UpdateUploadedList(filename, archive_path, upload_urls, debug)
def UploadSymbols(buildroot, board, official, cnt, failed_list):
"""Upload debug symbols for this build."""
log_cmd = ['upload_symbols', '--board', board]
if failed_list is not None:
log_cmd += ['--failed-list', str(failed_list)]
if official:
log_cmd.append('--official_build')
if cnt is not None:
log_cmd += ['--upload-limit', str(cnt)]
cros_build_lib.Info('Running: %s' % cros_build_lib.CmdToStr(log_cmd))
ret = upload_symbols.UploadSymbols(
board=board, official=official, upload_limit=cnt,
root=os.path.join(buildroot, constants.DEFAULT_CHROOT_DIR),
failed_list=failed_list)
if ret:
# TODO(davidjames): Convert this to a fatal error.
# See http://crbug.com/212437
cros_build_lib.PrintBuildbotStepWarnings()
def PushImages(board, archive_url, dryrun, profile, sign_types=()):
"""Push the generated image to the release bucket for signing."""
# Log the equivalent command for debugging purposes.
log_cmd = ['pushimage', '--board=%s' % board]
if dryrun:
log_cmd.append('-n')
if profile:
log_cmd.append('--profile=%s' % profile)
if sign_types:
log_cmd.append('--sign-types=%s' % ' '.join(sign_types))
log_cmd.append(archive_url)
cros_build_lib.Info('Running: %s' % cros_build_lib.CmdToStr(log_cmd))
try:
return pushimage.PushImage(archive_url, board, profile=profile,
sign_types=sign_types, dry_run=dryrun)
except pushimage.PushError as e:
cros_build_lib.PrintBuildbotStepFailure()
return e.args[1]
def BuildFactoryInstallImage(buildroot, board, extra_env):
"""Build a factory install image.
Args:
buildroot: Root directory where build occurs.
board: Board type that was built on this machine
extra_env: Flags to be added to the environment for the new process.
Returns:
The basename of the symlink created for the image.
"""
# We use build_attempt=3 here to ensure that this image uses a different
# output directory from our regular image and the factory test image.
alias = _FACTORY_SHIM
cmd = ['./build_image',
'--board=%s' % board,
'--replace',
'--symlink=%s' % alias,
'--build_attempt=3',
'factory_install']
RunBuildScript(buildroot, cmd, extra_env=extra_env, capture_output=True,
enter_chroot=True)
return alias
def MakeNetboot(buildroot, board, image_dir):
"""Build a netboot image.
Args:
buildroot: Root directory where build occurs.
board: Board type that was built on this machine.
image_dir: Directory containing factory install shim.
"""
cmd = ['./make_netboot.sh',
'--board=%s' % board,
'--image_dir=%s' % git.ReinterpretPathForChroot(image_dir)]
RunBuildScript(buildroot, cmd, capture_output=True, enter_chroot=True)
def MakeFactoryToolkit(buildroot, board, output_dir, version=None):
"""Build a factory toolkit.
Args:
buildroot: Root directory where build occurs.
board: Board type that was built on this machine.
output_dir: Directory for the resulting factory toolkit.
version: Version string to be included in ID string.
"""
cmd = ['./make_factory_toolkit.sh',
'--board=%s' % board,
'--output_dir=%s' % git.ReinterpretPathForChroot(output_dir)]
if version is not None:
cmd.extend(['--version', version])
RunBuildScript(buildroot, cmd, capture_output=True, enter_chroot=True)
def BuildRecoveryImage(buildroot, board, image_dir, extra_env):
"""Build a recovery image.
Args:
buildroot: Root directory where build occurs.
board: Board type that was built on this machine.
image_dir: Directory containing base image.
extra_env: Flags to be added to the environment for the new process.
"""
image = os.path.join(image_dir, constants.BASE_IMAGE_BIN)
cmd = ['./mod_image_for_recovery.sh',
'--board=%s' % board,
'--image=%s' % git.ReinterpretPathForChroot(image)]
RunBuildScript(buildroot, cmd, extra_env=extra_env, capture_output=True,
enter_chroot=True)
def BuildTarball(buildroot, input_list, tarball_output, cwd=None,
compressed=True, **kwargs):
"""Tars and zips files and directories from input_list to tarball_output.
Args:
buildroot: Root directory where build occurs.
input_list: A list of files and directories to be archived.
tarball_output: Path of output tar archive file.
cwd: Current working directory when tar command is executed.
compressed: Whether or not the tarball should be compressed with pbzip2.
**kwargs: Keyword arguments to pass to CreateTarball.
Returns:
Return value of cros_build_lib.CreateTarball.
"""
compressor = cros_build_lib.COMP_NONE
chroot = None
if compressed:
compressor = cros_build_lib.COMP_BZIP2
chroot = os.path.join(buildroot, 'chroot')
return cros_build_lib.CreateTarball(
tarball_output, cwd, compression=compressor, chroot=chroot,
inputs=input_list, **kwargs)
def FindFilesWithPattern(pattern, target='./', cwd=os.curdir):
"""Search the root directory recursively for matching filenames.
Args:
pattern: the pattern used to match the filenames.
target: the target directory to search.
cwd: current working directory.
Returns:
A list of paths of the matched files.
"""
# Backup the current working directory before changing it
old_cwd = os.getcwd()
os.chdir(cwd)
matches = []
for target, _, filenames in os.walk(target):
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.join(target, filename))
# Restore the working directory
os.chdir(old_cwd)
return matches
def BuildAUTestTarball(buildroot, board, work_dir, version, archive_url):
"""Tar up the au test artifacts into the tarball_dir.
Args:
buildroot: Root directory where build occurs.
board: Board type that was built on this machine.
work_dir: Location for doing work.
version: Basic version of the build i.e. 3289.23.0.
archive_url: GS directory where we uploaded payloads.
"""
au_test_tarball = os.path.join(work_dir, 'au_control.tar.bz2')
cwd = os.path.join(buildroot, 'src', 'third_party', 'autotest', 'files')
control_files_subdir = os.path.join('autotest', 'au_control_files')
autotest_dir = os.path.join(work_dir, control_files_subdir)
os.makedirs(autotest_dir)
# Get basic version without R*.
basic_version = re.search('R[0-9]+-([0-9][\w.]+)', version).group(1)
# Pass in the python paths to the libs full release test needs.
env_dict = dict(
chromite_path=buildroot,
devserver_path=os.path.join(buildroot, 'src', 'platform', 'dev'))
python_path = '%(chromite_path)s:%(devserver_path)s' % env_dict
cmd = ['site_utils/autoupdate/full_release_test.py',
'--npo', '--nmo', '--dump',
'--dump_dir', autotest_dir, '--archive_url', archive_url,
basic_version, board, '--log=debug']
gs_context_dir = os.path.dirname(gs.GSContext.GetDefaultGSUtilBin())
run_env = None
if not gs_context_dir in os.environ['PATH']:
run_env = os.environ.copy()
run_env['PATH'] += ':%s' % gs_context_dir
else:
run_env = os.environ
run_env.setdefault('PYTHONPATH', '')
run_env['PYTHONPATH'] += ':%s' % python_path
cros_build_lib.RunCommand(cmd, env=run_env, cwd=cwd)
BuildTarball(buildroot, [control_files_subdir], au_test_tarball, cwd=work_dir)
return au_test_tarball
def BuildFullAutotestTarball(buildroot, board, tarball_dir):
"""Tar up the full autotest directory into image_dir.
Args:
buildroot: Root directory where build occurs.
board: Board type that was built on this machine.
tarball_dir: Location for storing autotest tarballs.
Returns:
A tuple the path of the full autotest tarball.
"""
tarball = os.path.join(tarball_dir, 'autotest.tar.bz2')
cwd = os.path.abspath(os.path.join(buildroot, 'chroot', 'build', board,
constants.AUTOTEST_BUILD_PATH, '..'))
result = BuildTarball(buildroot, ['autotest'], tarball, cwd=cwd,
error_code_ok=True)
# Emerging the autotest package to the factory test image while this is
# running modifies the timestamp on /build/autotest/server by
# adding a tmp directory underneath it.
# When tar spots this, it flags this and returns
# status code 1. The tarball is still OK, although there might be a few
# unneeded (and garbled) tmp files. If tar fails in a different way, it'll
# return an error code other than 1.
# TODO: Fix the autotest ebuild. See http://crbug.com/237537
if result.returncode not in (0, 1):
raise Exception('Autotest tarball creation failed with exit code %s'
% (result.returncode))
return tarball
def BuildImageZip(archive_dir, image_dir):
"""Build image.zip in archive_dir from contents of image_dir.
Exclude the dev image from the zipfile.
Args:
archive_dir: Directory to store image.zip.
image_dir: Directory to zip up.
Returns:
The basename of the zipfile.
"""
filename = 'image.zip'
zipfile = os.path.join(archive_dir, filename)
cros_build_lib.RunCommand(['zip', zipfile, '-r', '.'], cwd=image_dir,
capture_output=True)
return filename
def BuildStandaloneArchive(archive_dir, image_dir, artifact_info):
"""Create a compressed archive from the specified image information.
The artifact info is derived from a JSON file in the board overlay. It
should be in the following format:
{
"artifacts": [
{ artifact },
{ artifact },
...
]
}
Each artifact can contain the following keys:
input - Required. A list of paths and globs that expands to
the list of files to archive.
output - the name of the archive to be created. If omitted,
it will default to the first filename, stripped of
extensions, plus the appropriate .tar.gz or other suffix.
archive - "tar" or "zip". If omitted, files will be uploaded
directly, without being archived together.
compress - a value cros_build_lib.CompressionStrToType knows about. Only
useful for tar. If omitted, an uncompressed tar will be created.
Args:
archive_dir: Directory to store image zip.
image_dir: Base path for all inputs.
artifact_info: Extended archive configuration dictionary containing:
- paths - required, list of files to archive.
- output, archive & compress entries from the JSON file.
Returns:
The base name of the archive.
Raises:
A ValueError if the compression or archive values are unknown.
A KeyError is a required field is missing from artifact_info.
"""
if 'archive' not in artifact_info:
# Nothing to do, just return the list as-is.
return artifact_info['paths']
inputs = artifact_info['paths']
archive = artifact_info['archive']
compress = artifact_info.get('compress')
compress_type = cros_build_lib.CompressionStrToType(compress)
if compress_type is None:
raise ValueError('unknown compression type: %s' % compress)
# If the output is fixed, use that. Otherwise, construct it
# from the name of the first archived file, stripping extensions.
filename = artifact_info.get(
'output', '%s.%s' % (os.path.splitext(inputs[0])[0], archive))
if archive == 'tar':
# Add the .compress extension if we don't have a fixed name.
if 'output' not in artifact_info and compress:
filename = "%s.%s" % (filename, compress)
extra_env = { 'XZ_OPT' : '-1' }
cros_build_lib.CreateTarball(
os.path.join(archive_dir, filename), image_dir,
inputs=inputs, compression=compress_type, extra_env=extra_env)
elif archive == 'zip':
cros_build_lib.RunCommand(
['zip', os.path.join(archive_dir, filename), '-r'] + inputs,
cwd=image_dir, capture_output=True)
else:
raise ValueError('unknown archive type: %s' % archive)
return [filename]
def BuildFirmwareArchive(buildroot, board, archive_dir):
"""Build firmware_from_source.tar.bz2 in archive_dir from build root.
Args:
buildroot: Root directory where build occurs.
board: Board name of build target.
archive_dir: Directory to store output file.
Returns:
The basename of the archived file, or None if the target board does
not have firmware from source.
"""
firmware_root = os.path.join(buildroot, 'chroot', 'build', board, 'firmware')
source_list = [os.path.relpath(f, firmware_root)
for f in glob.iglob(os.path.join(firmware_root, '*'))]
if not source_list:
return None
archive_name = 'firmware_from_source.tar.bz2'
archive_file = os.path.join(archive_dir, archive_name)
BuildTarball(buildroot, source_list, archive_file, cwd=firmware_root)
return archive_name
def BuildFactoryZip(buildroot, board, archive_dir, factory_shim_dir,
factory_toolkit_dir, version=None):
"""Build factory_image.zip in archive_dir.
Args:
buildroot: Root directory where build occurs.
board: Board name of build target.
archive_dir: Directory to store factory_image.zip.
factory_shim_dir: Directory containing factory shim.
factory_toolkit_dir: Directory containing factory toolkit.
version: The version string to be included in the factory image.zip.
Returns:
The basename of the zipfile.
"""
filename = 'factory_image.zip'
# Creates a staging temporary folder.
temp_dir = tempfile.mkdtemp(prefix='cbuildbot_factory')
zipfile = os.path.join(archive_dir, filename)
cmd = ['zip', '-r', zipfile, '.']
# Rules for archive: { folder: pattern }
rules = {
factory_shim_dir:
['*factory_install*.bin', '*partition*', os.path.join('netboot', '*')],
factory_toolkit_dir:
['*factory_image*.bin', '*partition*', 'install_factory_toolkit.run'],
}
for folder, patterns in rules.items():
if not folder or not os.path.exists(folder):
continue
basename = os.path.basename(folder)
target = os.path.join(temp_dir, basename)
os.symlink(folder, target)
for pattern in patterns:
cmd.extend(['--include', os.path.join(basename, pattern)])
# Everything in /usr/local/factory/bundle gets overlaid into the
# bundle.
bundle_src_dir = os.path.join(
buildroot, 'chroot', 'build', board, 'usr', 'local', 'factory', 'bundle')
if os.path.exists(bundle_src_dir):
for f in os.listdir(bundle_src_dir):
src_path = os.path.join(bundle_src_dir, f)
os.symlink(src_path, os.path.join(temp_dir, f))
cmd.extend(['--include',
f if os.path.isfile(src_path) else
os.path.join(f, '*')])
# Add a version file in the zip file.
if version is not None:
version_file = os.path.join(temp_dir, 'BUILD_VERSION')
osutils.WriteFile(version_file, version)
cmd.extend(['--include', version_file])
cros_build_lib.RunCommand(cmd, cwd=temp_dir, capture_output=True)
osutils.RmDir(temp_dir)
return filename
def ArchiveHWQual(buildroot, hwqual_name, archive_dir, image_dir):
"""Create a hwqual tarball in archive_dir.
Args:
buildroot: Root directory where build occurs.
hwqual_name: Name for tarball.
archive_dir: Local directory for hwqual tarball.
image_dir: Directory containing test image.
"""
scripts_dir = os.path.join(buildroot, 'src', 'scripts')
cmd = [os.path.join(scripts_dir, 'archive_hwqual'),
'--from', archive_dir,
'--image_dir', image_dir,
'--output_tag', hwqual_name]
cros_build_lib.RunCommand(cmd, capture_output=True)
return '%s.tar.bz2' % hwqual_name
def CreateTestRoot(build_root):
"""Returns a temporary directory for test results in chroot.
Returns:
The path inside the chroot rather than whole path.
"""
# Create test directory within tmp in chroot.
chroot = os.path.join(build_root, 'chroot')
chroot_tmp = os.path.join(chroot, 'tmp')
test_root = tempfile.mkdtemp(prefix='cbuildbot', dir=chroot_tmp)
# Path inside chroot.
return os.path.sep + os.path.relpath(test_root, start=chroot)
def GeneratePayloads(build_root, target_image_path, archive_dir):
"""Generates the payloads for hw testing.
Args:
build_root: The root of the chromium os checkout.
target_image_path: The path to the image to generate payloads to.
archive_dir: Where to store payloads we generated.
"""
real_target = os.path.realpath(target_image_path)
# The path to the target should look something like this:
# .../link/R37-5952.0.2014_06_12_2302-a1/chromiumos_test_image.bin
board, os_version = real_target.split('/')[-3:-1]
prefix = 'chromeos'
suffix = 'dev.bin'
cwd = os.path.join(build_root, 'src', 'scripts')
path = git.ReinterpretPathForChroot(
os.path.join(build_root, 'src', 'platform', 'dev', 'host'))
chroot_dir = os.path.join(build_root, 'chroot')
chroot_tmp = os.path.join(chroot_dir, 'tmp')
chroot_target = git.ReinterpretPathForChroot(target_image_path)
with osutils.TempDir(base_dir=chroot_tmp,
prefix='generate_payloads') as temp_dir:
chroot_temp_dir = temp_dir.replace(chroot_dir, '', 1)
cmd = [
os.path.join(path, 'cros_generate_update_payload'),
'--patch_kernel',
'--image', chroot_target,
'--output', os.path.join(chroot_temp_dir, 'update.gz')
]
cros_build_lib.RunCommand(cmd, enter_chroot=True, cwd=cwd)
name = '_'.join([prefix, os_version, board, 'full', suffix])
# Names for full payloads look something like this:
# chromeos_R37-5952.0.2014_06_12_2302-a1_link_full_dev.bin
shutil.move(os.path.join(temp_dir, 'update.gz'),
os.path.join(archive_dir, name))
cmd.extend(['--src_image', chroot_target])
cros_build_lib.RunCommand(cmd, enter_chroot=True, cwd=cwd)
# Names for delta payloads look something like this:
# chromeos_R37-5952.0.2014_06_12_2302-a1_R37-
# 5952.0.2014_06_12_2302-a1_link_delta_dev.bin
name = '_'.join([prefix, os_version, os_version, board, 'delta', suffix])
shutil.move(os.path.join(temp_dir, 'update.gz'),
os.path.join(archive_dir, name))
cmd = [
os.path.join(path, 'cros_generate_stateful_update_payload'),
'--image', chroot_target,
'--output', chroot_temp_dir
]
cros_build_lib.RunCommand(cmd, enter_chroot=True, cwd=cwd)
shutil.move(os.path.join(temp_dir, STATEFUL_FILE),
os.path.join(archive_dir, STATEFUL_FILE))
def GetChromeLKGM(svn_revision):
"""Returns the ChromeOS LKGM from Chrome given the SVN revision."""
svn_url = '/'.join([gclient.GetBaseURLs()[0], constants.SVN_CHROME_LKGM])
svn_revision_args = []
if svn_revision:
svn_revision_args = ['-r', str(svn_revision)]
svn_cmd = ['svn', 'cat', svn_url] + svn_revision_args
return cros_build_lib.RunCommand(svn_cmd, capture_output=True).output.strip()
def SyncChrome(build_root, chrome_root, useflags, tag=None, revision=None):
"""Sync chrome.
Args:
build_root: The root of the chromium os checkout.
chrome_root: The directory where chrome is stored.
useflags: Array of use flags.
tag: If supplied, the Chrome tag to sync.
revision: If supplied, the Chrome revision to sync.
"""
# --reset tells sync_chrome to blow away local changes and to feel
# free to delete any directories that get in the way of syncing. This
# is needed for unattended operation.
sync_chrome = os.path.join(build_root, 'chromite', 'bin', 'sync_chrome')
internal = constants.USE_CHROME_INTERNAL in useflags
cmd = [sync_chrome, '--reset']
cmd += ['--internal'] if internal else []
cmd += ['--tag', tag] if tag is not None else []
cmd += ['--revision', revision] if revision is not None else []
cmd += [chrome_root]
retry_util.RunCommandWithRetries(constants.SYNC_RETRIES, cmd, cwd=build_root)
def PatchChrome(chrome_root, patch, subdir):
"""Apply a patch to Chrome.
Args:
chrome_root: The directory where chrome is stored.
patch: Rietveld issue number to apply.
subdir: Subdirectory to apply patch in.
"""
cmd = ['apply_issue', '-i', patch]
cros_build_lib.RunCommand(cmd, cwd=os.path.join(chrome_root, subdir))
class ChromeSDK(object):
"""Wrapper for the 'cros chrome-sdk' command."""
DEFAULT_TARGETS = ('chrome', 'chrome_sandbox', 'nacl_helper',)
DEFAULT_JOBS = 24
DEFAULT_JOBS_GOMA = 500
def __init__(self, cwd, board, extra_args=None, chrome_src=None, goma=False,
debug_log=True, cache_dir=None, target_tc=None,
toolchain_url=None):
"""Initialization.
Args:
cwd: Where to invoke 'cros chrome-sdk'.
board: The board to run chrome-sdk for.
extra_args: Extra args to pass in on the command line.
chrome_src: Path to pass in with --chrome-src.
goma: If True, run using goma.
debug_log: If set, run with debug log-level.
cache_dir: Specify non-default cache directory.
target_tc: Override target toolchain.
toolchain_url: Override toolchain url pattern.
"""
self.cwd = cwd
self.board = board
self.extra_args = extra_args or []
if chrome_src:
self.extra_args += ['--chrome-src', chrome_src]
self.goma = goma
if not self.goma:
self.extra_args.append('--nogoma')
self.debug_log = debug_log
self.cache_dir = cache_dir
self.target_tc = target_tc
self.toolchain_url = toolchain_url
def Run(self, cmd, extra_args=None):
"""Run a command inside the chrome-sdk context."""
cros_cmd = ['cros']
if self.debug_log:
cros_cmd += ['--log-level', 'debug']
if self.cache_dir:
cros_cmd += ['--cache-dir', self.cache_dir]
if self.target_tc:
self.extra_args += ['--target-tc', self.target_tc]
if self.toolchain_url:
self.extra_args += ['--toolchain-url', self.toolchain_url]
cros_cmd += ['chrome-sdk', '--board', self.board] + self.extra_args
cros_cmd += (extra_args or []) + ['--'] + cmd
cros_build_lib.RunCommand(cros_cmd, cwd=self.cwd)
def Ninja(self, jobs=None, debug=False, targets=DEFAULT_TARGETS):
"""Run 'ninja' inside a chrome-sdk context.
Args:
jobs: The number of -j jobs to run.
debug: Whether to do a Debug build (defaults to Release).
targets: The targets to compile.
"""
if jobs is None:
jobs = self.DEFAULT_JOBS_GOMA if self.goma else self.DEFAULT_JOBS
flavor = 'Debug' if debug else 'Release'
cmd = ['ninja', '-C', 'out_%s/%s' % (self.board, flavor) , '-j', str(jobs)]
self.Run(cmd + list(targets))
|
<reponame>AllynH/Destiny_Read_Characters_Inventory_Vault
###################################################################################################
# Introduction: This program starts the foundation for an inventory management system - by doing 2 things:
# 1. Reads a characters equipped items and prints them to the screen.
# 2. Reads a your vault contents and creates a HTML page displaying the name, description, and image for each item in your vault.
#
# Important:
# In order to make this program work you'll need to add your username, password, api_key, destinyMembershipId and characterId in the Header_file.py
# For more details view the full blog post: http://allynh.com/blog/creating-a-python-app-for-destiny-part-5-reading-a-characters-inventory-and-vault-contents/
# For details on how to log into PSN view this blog post: http://allynh.com/blog/creating-a-python-app-for-destiny-part-3-logging-in-to-bungie-net-and-authenticating-with-psn/
#
# Usage: python equipItem.py
# Created by: <NAME> - www.AllynH.com
###################################################################################################
from PSN_login import login
import requests
import json
def transferItem(payload, session):
req_string = base_url + "TransferItem/"
print "Transferring item from vault to character..."
res = session.post(req_string, data=payload)
error_stat = res.json()['ErrorStatus'].decode('utf-8')
print "Error status: " + error_stat + "\n"
return res
def equipItem(payload, session):
# Send the request to equip the item:
equip_url = base_url + "EquipItem/"
print "Equipping item..."
res = session.post(equip_url, data=payload)
error_stat = res.json()['ErrorStatus'].decode('utf-8')
print "Error status: " + error_stat + "\n"
return res
def getVault(session):
getVault_url = base_url + membershipType + "/MyAccount/Vault/"
res = session.get(getVault_url, params={'accountId': destinyMembershipId})
print (res.url)
error_stat = res.json()['ErrorStatus'].decode('utf-8')
print "Error status: " + error_stat + "\n"
#print (res.status_code)
#print (res.text)
return res
def getCharacterInventory(session, charId):
req_string = base_url + membershipType + "/Account/" + destinyMembershipId + "/Character/" + charId + "/Inventory"
print "Fetching data for: " + req_string + "\n"
res = session.get(req_string)
error_stat = res.json()['ErrorStatus']
print "Error status: " + error_stat + "\n"
return res
def parseVault(session, vaultResult, all_data):
array_size = 0
weapon_list = [{
"membershipType": 2,
"itemReferenceHash": 0,
"itemId": 0,
"characterId": characterId_Warlock,
"stackSize": 1,
"transferToVault": False
} for array_size in range(vaultSize)]
array_size = 0
for bucket in vaultResult.json()['Response']['data']['buckets']:
#f.write (json.dumps(bucket['items'], indent=4))
for item in bucket['items']:
hashReqString = base_url + "Manifest/6/" + str(item['itemHash'])
weapon_list[array_size]['itemReferenceHash'] = item['itemHash']
weapon_list[array_size]['itemId'] = item['itemInstanceId']
inventoryItem = all_data['DestinyInventoryItemDefinition'][item['itemHash']]
item_name = inventoryItem['itemName']
item_tier = inventoryItem['tierTypeName']
item_type = inventoryItem['itemTypeName']
item_icon = inventoryItem['icon']
print "Item name is: " + item_name
array_size += 1
return weapon_list
def parseVaultHtml(session, vaultResult, all_data):
my_html = ""
array_size = 0
weapon_list = [{
"membershipType": 2,
"itemReferenceHash": 0,
"itemId": 0,
"characterId": characterId_Warlock,
"stackSize": 1,
"transferToVault": False
}
for array_size in range(vaultSize)]
array_size = 0
for bucket in vaultResult.json()['Response']['data']['buckets']:
for item in bucket['items']:
inventoryItem = all_data['DestinyInventoryItemDefinition'][item['itemHash']]
item_name = inventoryItem['itemName']
item_tier = inventoryItem['tierTypeName']
item_type = inventoryItem['itemTypeName']
item_icon = "http://www.bungie.net/" + inventoryItem['icon']
print "Item name is: " + item_name
array_size += 1
print "Item is: " + item_name
print "Item type is: " + item_tier + " " + item_type + "\n"
my_html = my_html + "\t\t<div class=\"col-md-4\">\n"
my_html = my_html + "\t\t\t<div class=\"thumbnail\">\n"
my_html = my_html + "\t\t\t\t<a href=\"" + item_icon + "\">\n"
my_html = my_html + "\t\t\t\t<img src=\"" + item_icon + "\">\n"
my_html = my_html + "\t\t\t\t</a>\n"
my_html = my_html + "\t\t\t\t<h3>" + item_name + "</h3>\n"
my_html = my_html + "\t\t\t\t<p>" + item_tier + " " + item_type + "</p>\n"
my_html = my_html + "\t\t\t</div>\n"
my_html = my_html + "\t\t</div>\n"
# Close the HTML file:
my_html = my_html + "\t</div> <!-- row -->\n"
my_html = my_html + "\t</div> <!-- container -->\n"
my_html = my_html + "</div> <!-- inventory-container -->\n"
my_html = my_html + "</body>\n"
my_html = my_html + "</html>\n"
return my_html
|
from os.path import abspath, basename, dirname, join
from firedrake import *
from incflow import *
import numpy as np
import pytest
set_log_level(DEBUG)
cwd = abspath(dirname(__file__))
data_dir = join(cwd, "data")
k = 0.02537 # W/(m*K)
rho = 1.225 # kg/m^3
cp = 1005.0 # J/(kg*K)
nu = 1.789 / rho * 1e-5 # m^2/s
g = 9.81 # m/s^2
thermal_expansion = 3.47e-3 # 1/K
# thermal_expansion = 1.0 / 293.0
T_cold = Constant(293.0)
T_hot = Constant(294.0)
N = 30
mesh = RectangleMesh(N, N, 0.1, 0.1)
x, y = SpatialCoordinate(mesh)
DG0 = FunctionSpace(mesh, "DG", 0)
incns = IncNavierStokes(mesh, nu=nu, rho=rho, solver_preset='asm')
eneq = EnergyEq(mesh, rho=rho, k=k, cp=cp)
incns.dt = 0.05
eneq.dt = incns.dt
W = incns.get_mixed_fs()
S = eneq.get_fs()
bcu_walls = DirichletBC(W.sub(0), Constant((0.0, 0.0)), (1, 2, 3, 4))
bcT = [
DirichletBC(S, T_cold, (1,)),
DirichletBC(S, T_hot, (2,))
]
# p_pin = DirichletBC(W.sub(1), Constant(0), (1,))
# p_pin.nodes = p_pin.nodes[:1]
incns.set_bcs(u_bcs=[bcu_walls],
p_bcs=[])
incns.has_nullspace = True
eneq.set_bcs(bcT)
incns.setup_solver()
eneq.setup_solver(W.sub(0))
eneq.T0.project(T_cold)
[bc.apply(eneq.T0) for bc in bcT]
eneq.T1.project(T_cold)
[bc.apply(eneq.T1) for bc in bcT]
outfile = File(join(data_dir, "../", "results/", "test_heated_cavity_decoupled.pvd"))
step = 0
t = 0.0
t_end = 50.0
num_timesteps = int(t_end / float(incns.dt))
output_frequency = 10
u1, p1 = incns.up1.split()
outfile.write(u1, p1, eneq.T1, time=t)
print("Number of timesteps: {}".format(num_timesteps))
print("Output frequency: {}".format(output_frequency))
print("Number of output files: {}".format(int(num_timesteps / output_frequency)))
print("DOFs: {}".format(incns.up0.vector().size() + eneq.T0.vector().size()))
# model.build_forcing_projector(as_vector([Constant(0.0), Constant(g)]) * Constant(thermal_expansion) * (model.T1 - T_cold))
while t <= t_end:
with Timer('Step'):
t += float(incns.dt)
printp0("***********************")
printp0("Time {:.3E}".format(t))
printp0("Timestep {:.3E}".format(float(incns.dt)))
incns.set_forcing(
as_vector([Constant(0.0), Constant(g)]) * Constant(thermal_expansion) * (eneq.T1 - T_cold)
)
u1, p1 = incns.step()
T1 = eneq.step(u1)
cfl = project(sqrt(inner(u1, u1)) * incns.dt / CellVolume(mesh), DG0)
max_cfl = np.max(cfl.vector().array())
print('CFL: {:+.5E}'.format(max_cfl))
if step % output_frequency == 0:
outfile.write(u1, p1, T1, time=t)
step += 1
printp0("")
|
#!/usr/sbin/env python
import click
import ipaddress
import json
import jsonpatch
import netaddr
import netifaces
import os
import re
import subprocess
import sys
import time
import itertools
from collections import OrderedDict
from generic_config_updater.generic_updater import GenericUpdater, ConfigFormat
from minigraph import parse_device_desc_xml
from natsort import natsorted
from portconfig import get_child_ports
from socket import AF_INET, AF_INET6
from sonic_py_common import device_info, multi_asic
from sonic_py_common.interface import get_interface_table_name, get_port_table_name, get_intf_longname
from utilities_common import util_base
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from utilities_common.db import Db
from utilities_common.intf_filter import parse_interface_in_filter
from utilities_common import bgp_util
import utilities_common.cli as clicommon
from utilities_common.general import load_db_config
from .utils import log
from . import aaa
from . import chassis_modules
from . import console
from . import feature
from . import kdump
from . import kube
from . import muxcable
from . import nat
from . import vlan
from . import vxlan
from . import plugins
from .config_mgmt import ConfigMgmtDPB
from . import mclag
# mock masic APIs for unit test
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "1" or os.environ["UTILITIES_UNIT_TESTING"] == "2":
modules_path = os.path.join(os.path.dirname(__file__), "..")
tests_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, tests_path)
import mock_tables.dbconnector
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
import mock_tables.mock_multi_asic
mock_tables.dbconnector.load_namespace_config()
except KeyError:
pass
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?'])
SONIC_GENERATED_SERVICE_PATH = '/etc/sonic/generated_services.conf'
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
VLAN_SUB_INTERFACE_SEPARATOR = '.'
ASIC_CONF_FILENAME = 'asic.conf'
DEFAULT_CONFIG_DB_FILE = '/etc/sonic/config_db.json'
DEFAULT_CONFIG_YANG_FILE = '/etc/sonic/config_yang.json'
NAMESPACE_PREFIX = 'asic'
INTF_KEY = "interfaces"
INIT_CFG_FILE = '/etc/sonic/init_cfg.json'
DEFAULT_NAMESPACE = ''
CFG_LOOPBACK_PREFIX = "Loopback"
CFG_LOOPBACK_PREFIX_LEN = len(CFG_LOOPBACK_PREFIX)
CFG_LOOPBACK_NAME_TOTAL_LEN_MAX = 11
CFG_LOOPBACK_ID_MAX_VAL = 999
CFG_LOOPBACK_NO="<0-999>"
CFG_PORTCHANNEL_PREFIX = "PortChannel"
CFG_PORTCHANNEL_PREFIX_LEN = 11
CFG_PORTCHANNEL_NAME_TOTAL_LEN_MAX = 15
CFG_PORTCHANNEL_MAX_VAL = 9999
CFG_PORTCHANNEL_NO="<0-9999>"
PORT_MTU = "mtu"
PORT_SPEED = "speed"
PORT_TPID = "tpid"
DEFAULT_TPID = "0x8100"
asic_type = None
DSCP_RANGE = click.IntRange(min=0, max=63)
TTL_RANGE = click.IntRange(min=0, max=255)
QUEUE_RANGE = click.IntRange(min=0, max=255)
GRE_TYPE_RANGE = click.IntRange(min=0, max=65535)
#
# Helper functions
#
# Sort nested dict
def sort_dict(data):
""" Sort of 1st level and 2nd level dict of data naturally by its key
data: data to be sorted
"""
if type(data) is not dict:
return data
for table in data:
if type(data[table]) is dict:
data[table] = OrderedDict(natsorted(data[table].items()))
return OrderedDict(natsorted(data.items()))
# Read given JSON file
def read_json_file(fileName):
try:
with open(fileName) as f:
result = json.load(f)
except Exception as e:
raise Exception(str(e))
return result
def _get_breakout_options(ctx, args, incomplete):
""" Provides dynamic mode option as per user argument i.e. interface name """
all_mode_options = []
interface_name = args[-1]
breakout_cfg_file = device_info.get_path_to_port_config_file()
if not os.path.isfile(breakout_cfg_file) or not breakout_cfg_file.endswith('.json'):
return []
else:
breakout_file_input = read_json_file(breakout_cfg_file)
if interface_name in breakout_file_input[INTF_KEY]:
breakout_mode_options = [mode for i, v in breakout_file_input[INTF_KEY].items() if i == interface_name \
for mode in v["breakout_modes"].keys()]
all_mode_options = [str(c) for c in breakout_mode_options if incomplete in c]
return all_mode_options
def _validate_interface_mode(ctx, breakout_cfg_file, interface_name, target_brkout_mode, cur_brkout_mode):
""" Validate Parent interface and user selected mode before starting deletion or addition process """
breakout_file_input = read_json_file(breakout_cfg_file)["interfaces"]
if interface_name not in breakout_file_input:
click.secho("[ERROR] {} is not a Parent port. So, Breakout Mode is not available on this port".format(interface_name), fg='red')
return False
# Check whether target breakout mode is available for the user-selected interface or not
if target_brkout_mode not in breakout_file_input[interface_name]["breakout_modes"].keys():
click.secho('[ERROR] Target mode {} is not available for the port {}'. format(target_brkout_mode, interface_name), fg='red')
return False
# Get config db context
config_db = ctx.obj['config_db']
port_dict = config_db.get_table('PORT')
# Check whether there is any port in config db.
if not port_dict:
click.echo("port_dict is None!")
return False
# Check whether the user-selected interface is part of 'port' table in config db.
if interface_name not in port_dict:
click.secho("[ERROR] {} is not in port_dict".format(interface_name))
return False
click.echo("\nRunning Breakout Mode : {} \nTarget Breakout Mode : {}".format(cur_brkout_mode, target_brkout_mode))
if (cur_brkout_mode == target_brkout_mode):
click.secho("[WARNING] No action will be taken as current and desired Breakout Mode are same.", fg='magenta')
sys.exit(0)
return True
def load_ConfigMgmt(verbose):
""" Load config for the commands which are capable of change in config DB. """
try:
cm = ConfigMgmtDPB(debug=verbose)
return cm
except Exception as e:
raise Exception("Failed to load the config. Error: {}".format(str(e)))
def breakout_warnUser_extraTables(cm, final_delPorts, confirm=True):
"""
Function to warn user about extra tables while Dynamic Port Breakout(DPB).
confirm: re-confirm from user to proceed.
Config Tables Without Yang model considered extra tables.
cm = instance of config MGMT class.
"""
try:
# check if any extra tables exist
eTables = cm.tablesWithOutYang()
if len(eTables):
# find relavent tables in extra tables, i.e. one which can have deleted
# ports
tables = cm.configWithKeys(configIn=eTables, keys=final_delPorts)
click.secho("Below Config can not be verified, It may cause harm "\
"to the system\n {}".format(json.dumps(tables, indent=2)))
click.confirm('Do you wish to Continue?', abort=True)
except Exception as e:
raise Exception("Failed in breakout_warnUser_extraTables. Error: {}".format(str(e)))
return
def breakout_Ports(cm, delPorts=list(), portJson=dict(), force=False, \
loadDefConfig=False, verbose=False):
deps, ret = cm.breakOutPort(delPorts=delPorts, portJson=portJson, \
force=force, loadDefConfig=loadDefConfig)
# check if DPB failed
if ret == False:
if not force and deps:
click.echo("Dependecies Exist. No further action will be taken")
click.echo("*** Printing dependecies ***")
for dep in deps:
click.echo(dep)
sys.exit(0)
else:
click.echo("[ERROR] Port breakout Failed!!! Opting Out")
raise click.Abort()
return
#
# Helper functions
#
def _get_device_type():
"""
Get device type
TODO: move to sonic-py-common
"""
command = "{} -m -v DEVICE_METADATA.localhost.type".format(SONIC_CFGGEN_PATH)
proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE)
device_type, err = proc.communicate()
if err:
click.echo("Could not get the device type from minigraph, setting device type to Unknown")
device_type = 'Unknown'
else:
device_type = device_type.strip()
return device_type
def interface_alias_to_name(config_db, interface_alias):
"""Return default interface name if alias name is given as argument
"""
vlan_id = ""
sub_intf_sep_idx = -1
if interface_alias is not None:
sub_intf_sep_idx = interface_alias.find(VLAN_SUB_INTERFACE_SEPARATOR)
if sub_intf_sep_idx != -1:
vlan_id = interface_alias[sub_intf_sep_idx + 1:]
# interface_alias holds the parent port name so the subsequent logic still applies
interface_alias = interface_alias[:sub_intf_sep_idx]
# If the input parameter config_db is None, derive it from interface.
# In single ASIC platform, get_port_namespace() returns DEFAULT_NAMESPACE.
if config_db is None:
namespace = get_port_namespace(interface_alias)
if namespace is None:
return None
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
port_dict = config_db.get_table('PORT')
if interface_alias is not None:
if not port_dict:
click.echo("port_dict is None!")
raise click.Abort()
for port_name in port_dict:
if interface_alias == port_dict[port_name]['alias']:
return port_name if sub_intf_sep_idx == -1 else port_name + VLAN_SUB_INTERFACE_SEPARATOR + vlan_id
# Interface alias not in port_dict, just return interface_alias, e.g.,
# portchannel is passed in as argument, which does not have an alias
return interface_alias if sub_intf_sep_idx == -1 else interface_alias + VLAN_SUB_INTERFACE_SEPARATOR + vlan_id
def interface_name_is_valid(config_db, interface_name):
"""Check if the interface name is valid
"""
# If the input parameter config_db is None, derive it from interface.
# In single ASIC platform, get_port_namespace() returns DEFAULT_NAMESPACE.
if config_db is None:
namespace = get_port_namespace(interface_name)
if namespace is None:
return False
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
port_dict = config_db.get_table('PORT')
port_channel_dict = config_db.get_table('PORTCHANNEL')
sub_port_intf_dict = config_db.get_table('VLAN_SUB_INTERFACE')
loopback_dict = config_db.get_table('LOOPBACK_INTERFACE')
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is not None:
if not port_dict:
click.echo("port_dict is None!")
raise click.Abort()
for port_name in port_dict:
if interface_name == port_name:
return True
if port_channel_dict:
for port_channel_name in port_channel_dict:
if interface_name == port_channel_name:
return True
if sub_port_intf_dict:
for sub_port_intf_name in sub_port_intf_dict:
if interface_name == sub_port_intf_name:
return True
if loopback_dict:
for loopback_name in loopback_dict:
if interface_name == loopback_name:
return True
return False
def interface_name_to_alias(config_db, interface_name):
"""Return alias interface name if default name is given as argument
"""
# If the input parameter config_db is None, derive it from interface.
# In single ASIC platform, get_port_namespace() returns DEFAULT_NAMESPACE.
if config_db is None:
namespace = get_port_namespace(interface_name)
if namespace is None:
return None
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
port_dict = config_db.get_table('PORT')
if interface_name is not None:
if not port_dict:
click.echo("port_dict is None!")
raise click.Abort()
for port_name in port_dict:
if interface_name == port_name:
return port_dict[port_name]['alias']
return None
def get_interface_ipaddresses(config_db, interface_name):
"""Get IP addresses attached to interface
"""
ipaddresses = set()
table_name = get_interface_table_name(interface_name)
if not table_name:
return ipaddresses
keys = config_db.get_keys(table_name)
for key in keys:
if isinstance(key, tuple) and len(key) == 2:
iface, interface_ip = key
if iface == interface_name:
ipaddresses.add(ipaddress.ip_interface(interface_ip))
return ipaddresses
def is_interface_bind_to_vrf(config_db, interface_name):
"""Get interface if bind to vrf or not
"""
table_name = get_interface_table_name(interface_name)
if table_name == "":
return False
entry = config_db.get_entry(table_name, interface_name)
if entry and entry.get("vrf_name"):
return True
return False
def is_portchannel_name_valid(portchannel_name):
"""Port channel name validation
"""
# Return True if Portchannel name is PortChannelXXXX (XXXX can be 0-9999)
if portchannel_name[:CFG_PORTCHANNEL_PREFIX_LEN] != CFG_PORTCHANNEL_PREFIX :
return False
if (portchannel_name[CFG_PORTCHANNEL_PREFIX_LEN:].isdigit() is False or
int(portchannel_name[CFG_PORTCHANNEL_PREFIX_LEN:]) > CFG_PORTCHANNEL_MAX_VAL) :
return False
if len(portchannel_name) > CFG_PORTCHANNEL_NAME_TOTAL_LEN_MAX:
return False
return True
def is_portchannel_present_in_db(db, portchannel_name):
"""Check if Portchannel is present in Config DB
"""
# Return True if Portchannel name exists in the CONFIG_DB
portchannel_list = db.get_table(CFG_PORTCHANNEL_PREFIX)
if portchannel_list is None:
return False
if portchannel_name in portchannel_list:
return True
return False
def is_port_member_of_this_portchannel(db, port_name, portchannel_name):
"""Check if a port is member of given portchannel
"""
portchannel_list = db.get_table(CFG_PORTCHANNEL_PREFIX)
if portchannel_list is None:
return False
for k,v in db.get_table('PORTCHANNEL_MEMBER'):
if (k == portchannel_name) and (v == port_name):
return True
return False
# Return the namespace where an interface belongs
# The port name input could be in default mode or in alias mode.
def get_port_namespace(port):
# If it is a non multi-asic platform, or if the interface is management interface
# return DEFAULT_NAMESPACE
if not multi_asic.is_multi_asic() or port == 'eth0':
return DEFAULT_NAMESPACE
# Get the table to check for interface presence
table_name = get_port_table_name(port)
if table_name == "":
return None
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns'] + ns_list['back_ns']
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
# If the interface naming mode is alias, search the tables for alias_name.
if clicommon.get_interface_naming_mode() == "alias":
port_dict = config_db.get_table(table_name)
if port_dict:
for port_name in port_dict:
if port == port_dict[port_name]['alias']:
return namespace
else:
entry = config_db.get_entry(table_name, port)
if entry:
return namespace
return None
def del_interface_bind_to_vrf(config_db, vrf_name):
"""del interface bind to vrf
"""
tables = ['INTERFACE', 'PORTCHANNEL_INTERFACE', 'VLAN_INTERFACE', 'LOOPBACK_INTERFACE']
for table_name in tables:
interface_dict = config_db.get_table(table_name)
if interface_dict:
for interface_name in interface_dict:
if 'vrf_name' in interface_dict[interface_name] and vrf_name == interface_dict[interface_name]['vrf_name']:
interface_ipaddresses = get_interface_ipaddresses(config_db, interface_name)
for ipaddress in interface_ipaddresses:
remove_router_interface_ip_address(config_db, interface_name, ipaddress)
config_db.set_entry(table_name, interface_name, None)
def set_interface_naming_mode(mode):
"""Modify SONIC_CLI_IFACE_MODE env variable in user .bashrc
"""
user = os.getenv('SUDO_USER')
bashrc_ifacemode_line = "export SONIC_CLI_IFACE_MODE={}".format(mode)
# In case of multi-asic, we can check for the alias mode support in any of
# the namespaces as this setting of alias mode should be identical everywhere.
# Here by default we set the namespaces to be a list just having '' which
# represents the linux host. In case of multi-asic, we take the first namespace
# created for the front facing ASIC.
namespaces = [DEFAULT_NAMESPACE]
if multi_asic.is_multi_asic():
namespaces = multi_asic.get_all_namespaces()['front_ns']
# Ensure all interfaces have an 'alias' key in PORT dict
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespaces[0])
config_db.connect()
port_dict = config_db.get_table('PORT')
if not port_dict:
click.echo("port_dict is None!")
raise click.Abort()
for port_name in port_dict:
try:
if port_dict[port_name]['alias']:
pass
except KeyError:
click.echo("Platform does not support alias mapping")
raise click.Abort()
if not user:
user = os.getenv('USER')
if user != "root":
bashrc = "/home/{}/.bashrc".format(user)
else:
click.get_current_context().fail("Cannot set interface naming mode for root user!")
f = open(bashrc, 'r')
filedata = f.read()
f.close()
if "SONIC_CLI_IFACE_MODE" not in filedata:
newdata = filedata + bashrc_ifacemode_line
newdata += "\n"
else:
newdata = re.sub(r"export SONIC_CLI_IFACE_MODE=\w+",
bashrc_ifacemode_line, filedata)
f = open(bashrc, 'w')
f.write(newdata)
f.close()
click.echo("Please logout and log back in for changes take effect.")
def get_intf_ipv6_link_local_mode(ctx, interface_name, table_name):
config_db = ctx.obj["config_db"]
intf = config_db.get_table(table_name)
if interface_name in intf:
if 'ipv6_use_link_local_only' in intf[interface_name]:
return intf[interface_name]['ipv6_use_link_local_only']
else:
return "disable"
else:
return ""
def _is_neighbor_ipaddress(config_db, ipaddress):
"""Returns True if a neighbor has the IP address <ipaddress>, False if not
"""
entry = config_db.get_entry('BGP_NEIGHBOR', ipaddress)
return True if entry else False
def _get_all_neighbor_ipaddresses(config_db):
"""Returns list of strings containing IP addresses of all BGP neighbors
"""
addrs = []
bgp_sessions = config_db.get_table('BGP_NEIGHBOR')
for addr, session in bgp_sessions.items():
addrs.append(addr)
return addrs
def _get_neighbor_ipaddress_list_by_hostname(config_db, hostname):
"""Returns list of strings, each containing an IP address of neighbor with
hostname <hostname>. Returns empty list if <hostname> not a neighbor
"""
addrs = []
bgp_sessions = config_db.get_table('BGP_NEIGHBOR')
for addr, session in bgp_sessions.items():
if 'name' in session and session['name'] == hostname:
addrs.append(addr)
return addrs
def _change_bgp_session_status_by_addr(config_db, ipaddress, status, verbose):
"""Start up or shut down BGP session by IP address
"""
verb = 'Starting' if status == 'up' else 'Shutting'
click.echo("{} {} BGP session with neighbor {}...".format(verb, status, ipaddress))
config_db.mod_entry('bgp_neighbor', ipaddress, {'admin_status': status})
def _change_bgp_session_status(config_db, ipaddr_or_hostname, status, verbose):
"""Start up or shut down BGP session by IP address or hostname
"""
ip_addrs = []
# If we were passed an IP address, convert it to lowercase because IPv6 addresses were
# stored in ConfigDB with all lowercase alphabet characters during minigraph parsing
if _is_neighbor_ipaddress(config_db, ipaddr_or_hostname.lower()):
ip_addrs.append(ipaddr_or_hostname.lower())
else:
# If <ipaddr_or_hostname> is not the IP address of a neighbor, check to see if it's a hostname
ip_addrs = _get_neighbor_ipaddress_list_by_hostname(config_db, ipaddr_or_hostname)
if not ip_addrs:
return False
for ip_addr in ip_addrs:
_change_bgp_session_status_by_addr(config_db, ip_addr, status, verbose)
return True
def _validate_bgp_neighbor(config_db, neighbor_ip_or_hostname):
"""validates whether the given ip or host name is a BGP neighbor
"""
ip_addrs = []
if _is_neighbor_ipaddress(config_db, neighbor_ip_or_hostname.lower()):
ip_addrs.append(neighbor_ip_or_hostname.lower())
else:
ip_addrs = _get_neighbor_ipaddress_list_by_hostname(config_db, neighbor_ip_or_hostname.upper())
return ip_addrs
def _remove_bgp_neighbor_config(config_db, neighbor_ip_or_hostname):
"""Removes BGP configuration of the given neighbor
"""
ip_addrs = _validate_bgp_neighbor(config_db, neighbor_ip_or_hostname)
if not ip_addrs:
return False
for ip_addr in ip_addrs:
config_db.mod_entry('bgp_neighbor', ip_addr, None)
click.echo("Removed configuration of BGP neighbor {}".format(ip_addr))
return True
def _change_hostname(hostname):
current_hostname = os.uname()[1]
if current_hostname != hostname:
clicommon.run_command('echo {} > /etc/hostname'.format(hostname), display_cmd=True)
clicommon.run_command('hostname -F /etc/hostname', display_cmd=True)
clicommon.run_command(r'sed -i "/\s{}$/d" /etc/hosts'.format(current_hostname), display_cmd=True)
clicommon.run_command('echo "127.0.0.1 {}" >> /etc/hosts'.format(hostname), display_cmd=True)
def _clear_cbf():
CBF_TABLE_NAMES = [
'DSCP_TO_FC_MAP',
'EXP_TO_FC_MAP']
namespace_list = [DEFAULT_NAMESPACE]
if multi_asic.get_num_asics() > 1:
namespace_list = multi_asic.get_namespaces_from_linux()
for ns in namespace_list:
if ns is DEFAULT_NAMESPACE:
config_db = ConfigDBConnector()
else:
config_db = ConfigDBConnector(
use_unix_socket_path=True, namespace=ns
)
config_db.connect()
for cbf_table in CBF_TABLE_NAMES:
config_db.delete_table(cbf_table)
def _clear_qos():
QOS_TABLE_NAMES = [
'PORT_QOS_MAP',
'QUEUE',
'TC_TO_PRIORITY_GROUP_MAP',
'MAP_PFC_PRIORITY_TO_QUEUE',
'TC_TO_QUEUE_MAP',
'DSCP_TO_TC_MAP',
'MPLS_TC_TO_TC_MAP',
'SCHEDULER',
'PFC_PRIORITY_TO_PRIORITY_GROUP_MAP',
'WRED_PROFILE',
'CABLE_LENGTH',
'BUFFER_PG',
'BUFFER_QUEUE',
'BUFFER_PORT_INGRESS_PROFILE_LIST',
'BUFFER_PORT_EGRESS_PROFILE_LIST',
'BUFFER_PROFILE',
'BUFFER_POOL',
'DEFAULT_LOSSLESS_BUFFER_PARAMETER',
'LOSSLESS_TRAFFIC_PATTERN']
namespace_list = [DEFAULT_NAMESPACE]
if multi_asic.get_num_asics() > 1:
namespace_list = multi_asic.get_namespaces_from_linux()
for ns in namespace_list:
if ns is DEFAULT_NAMESPACE:
config_db = ConfigDBConnector()
else:
config_db = ConfigDBConnector(
use_unix_socket_path=True, namespace=ns
)
config_db.connect()
for qos_table in QOS_TABLE_NAMES:
config_db.delete_table(qos_table)
def _get_sonic_generated_services(num_asic):
if not os.path.isfile(SONIC_GENERATED_SERVICE_PATH):
return None
generated_services_list = []
generated_multi_instance_services = []
with open(SONIC_GENERATED_SERVICE_PATH) as generated_service_file:
for line in generated_service_file:
if '@' in line:
line = line.replace('@', '')
if num_asic > 1:
generated_multi_instance_services.append(line.rstrip('\n'))
else:
generated_services_list.append(line.rstrip('\n'))
else:
generated_services_list.append(line.rstrip('\n'))
return generated_services_list, generated_multi_instance_services
# Callback for confirmation prompt. Aborts if user enters "n"
def _abort_if_false(ctx, param, value):
if not value:
ctx.abort()
def _get_disabled_services_list(config_db):
disabled_services_list = []
feature_table = config_db.get_table('FEATURE')
if feature_table is not None:
for feature_name in feature_table:
if not feature_name:
log.log_warning("Feature is None")
continue
state = feature_table[feature_name]['state']
if not state:
log.log_warning("Enable state of feature '{}' is None".format(feature_name))
continue
if state == "disabled":
disabled_services_list.append(feature_name)
else:
log.log_warning("Unable to retreive FEATURE table")
return disabled_services_list
def _stop_services():
try:
subprocess.check_call("sudo monit status", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
click.echo("Disabling container monitoring ...")
clicommon.run_command("sudo monit unmonitor container_checker")
except subprocess.CalledProcessError as err:
pass
click.echo("Stopping SONiC target ...")
clicommon.run_command("sudo systemctl stop sonic.target --job-mode replace-irreversibly")
def _get_sonic_services():
out = clicommon.run_command("systemctl list-dependencies --plain sonic.target | sed '1d'", return_cmd=True)
return (unit.strip() for unit in out.splitlines())
def _get_delayed_sonic_services():
rc1 = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
rc2 = clicommon.run_command("systemctl is-enabled {}".format(rc1.replace("\n", " ")), return_cmd=True)
timer = [line.strip() for line in rc1.splitlines()]
state = [line.strip() for line in rc2.splitlines()]
services = []
for unit in timer:
if state[timer.index(unit)] == "enabled":
services.append(unit.rstrip(".timer"))
return services
def _reset_failed_services():
for service in itertools.chain(_get_sonic_services(), _get_delayed_sonic_services()):
clicommon.run_command("systemctl reset-failed {}".format(service))
def _restart_services():
click.echo("Restarting SONiC target ...")
clicommon.run_command("sudo systemctl restart sonic.target")
try:
subprocess.check_call("sudo monit status", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
click.echo("Enabling container monitoring ...")
clicommon.run_command("sudo monit monitor container_checker")
except subprocess.CalledProcessError as err:
pass
# Reload Monit configuration to pick up new hostname in case it changed
click.echo("Reloading Monit configuration ...")
clicommon.run_command("sudo monit reload")
def _get_delay_timers():
out = clicommon.run_command("systemctl list-dependencies sonic-delayed.target --plain |sed '1d'", return_cmd=True)
return [timer.strip() for timer in out.splitlines()]
def _delay_timers_elapsed():
for timer in _get_delay_timers():
out = clicommon.run_command("systemctl show {} --property=LastTriggerUSecMonotonic --value".format(timer), return_cmd=True)
if out.strip() == "0":
return False
return True
def _per_namespace_swss_ready(service_name):
out = clicommon.run_command("systemctl show {} --property ActiveState --value".format(service_name), return_cmd=True)
if out.strip() != "active":
return False
out = clicommon.run_command("systemctl show {} --property ActiveEnterTimestampMonotonic --value".format(service_name), return_cmd=True)
swss_up_time = float(out.strip())/1000000
now = time.monotonic()
if (now - swss_up_time > 120):
return True
else:
return False
def _swss_ready():
list_of_swss = []
num_asics = multi_asic.get_num_asics()
if num_asics == 1:
list_of_swss.append("swss.service")
else:
for asic in range(num_asics):
service = "swss@{}.service".format(asic)
list_of_swss.append(service)
for service_name in list_of_swss:
if _per_namespace_swss_ready(service_name) == False:
return False
return True
def _is_system_starting():
out = clicommon.run_command("sudo systemctl is-system-running", return_cmd=True)
return out.strip() == "starting"
def interface_is_in_vlan(vlan_member_table, interface_name):
""" Check if an interface is in a vlan """
for _, intf in vlan_member_table:
if intf == interface_name:
return True
return False
def interface_is_in_portchannel(portchannel_member_table, interface_name):
""" Check if an interface is part of portchannel """
for _, intf in portchannel_member_table:
if intf == interface_name:
return True
return False
def interface_has_mirror_config(mirror_table, interface_name):
""" Check if port is already configured with mirror config """
for _, v in mirror_table.items():
if 'src_port' in v and v['src_port'] == interface_name:
return True
if 'dst_port' in v and v['dst_port'] == interface_name:
return True
return False
def validate_mirror_session_config(config_db, session_name, dst_port, src_port, direction):
""" Check if SPAN mirror-session config is valid """
if len(config_db.get_entry('MIRROR_SESSION', session_name)) != 0:
click.echo("Error: {} already exists".format(session_name))
return False
vlan_member_table = config_db.get_table('VLAN_MEMBER')
mirror_table = config_db.get_table('MIRROR_SESSION')
portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')
if dst_port:
if not interface_name_is_valid(config_db, dst_port):
click.echo("Error: Destination Interface {} is invalid".format(dst_port))
return False
if interface_is_in_vlan(vlan_member_table, dst_port):
click.echo("Error: Destination Interface {} has vlan config".format(dst_port))
return False
if interface_has_mirror_config(mirror_table, dst_port):
click.echo("Error: Destination Interface {} already has mirror config".format(dst_port))
return False
if interface_is_in_portchannel(portchannel_member_table, dst_port):
click.echo("Error: Destination Interface {} has portchannel config".format(dst_port))
return False
if clicommon.is_port_router_interface(config_db, dst_port):
click.echo("Error: Destination Interface {} is a L3 interface".format(dst_port))
return False
if src_port:
for port in src_port.split(","):
if not interface_name_is_valid(config_db, port):
click.echo("Error: Source Interface {} is invalid".format(port))
return False
if dst_port and dst_port == port:
click.echo("Error: Destination Interface cant be same as Source Interface")
return False
if interface_has_mirror_config(mirror_table, port):
click.echo("Error: Source Interface {} already has mirror config".format(port))
return False
if direction:
if direction not in ['rx', 'tx', 'both']:
click.echo("Error: Direction {} is invalid".format(direction))
return False
return True
def cli_sroute_to_config(ctx, command_str, strict_nh = True):
if len(command_str) < 2 or len(command_str) > 9:
ctx.fail("argument is not in pattern prefix [vrf <vrf_name>] <A.B.C.D/M> nexthop <[vrf <vrf_name>] <A.B.C.D>>|<dev <dev_name>>!")
if "prefix" not in command_str:
ctx.fail("argument is incomplete, prefix not found!")
if "nexthop" not in command_str and strict_nh:
ctx.fail("argument is incomplete, nexthop not found!")
nexthop_str = None
config_entry = {}
vrf_name = ""
if "nexthop" in command_str:
idx = command_str.index("nexthop")
prefix_str = command_str[:idx]
nexthop_str = command_str[idx:]
else:
prefix_str = command_str[:]
if prefix_str:
if 'prefix' in prefix_str and 'vrf' in prefix_str:
# prefix_str: ['prefix', 'vrf', Vrf-name, ip]
vrf_name = prefix_str[2]
ip_prefix = prefix_str[3]
elif 'prefix' in prefix_str:
# prefix_str: ['prefix', ip]
ip_prefix = prefix_str[1]
else:
ctx.fail("prefix is not in pattern!")
if nexthop_str:
if 'nexthop' in nexthop_str and 'vrf' in nexthop_str:
# nexthop_str: ['nexthop', 'vrf', Vrf-name, ip]
config_entry["nexthop"] = nexthop_str[3]
config_entry["nexthop-vrf"] = nexthop_str[2]
elif 'nexthop' in nexthop_str and 'dev' in nexthop_str:
# nexthop_str: ['nexthop', 'dev', ifname]
config_entry["ifname"] = nexthop_str[2]
elif 'nexthop' in nexthop_str:
# nexthop_str: ['nexthop', ip]
config_entry["nexthop"] = nexthop_str[1]
else:
ctx.fail("nexthop is not in pattern!")
try:
ipaddress.ip_network(ip_prefix)
if 'nexthop' in config_entry:
nh_list = config_entry['nexthop'].split(',')
for nh in nh_list:
# Nexthop to portchannel
if nh.startswith('PortChannel'):
config_db = ctx.obj['config_db']
if not nh in config_db.get_keys('PORTCHANNEL'):
ctx.fail("portchannel does not exist.")
else:
ipaddress.ip_address(nh)
except ValueError:
ctx.fail("ip address is not valid.")
if not vrf_name == "":
key = vrf_name + "|" + ip_prefix
else:
key = ip_prefix
return key, config_entry
def update_sonic_environment():
"""Prepare sonic environment variable using SONiC environment template file.
"""
SONIC_ENV_TEMPLATE_FILE = os.path.join('/', "usr", "share", "sonic", "templates", "sonic-environment.j2")
SONIC_VERSION_YML_FILE = os.path.join('/', "etc", "sonic", "sonic_version.yml")
SONIC_ENV_FILE = os.path.join('/', "etc", "sonic", "sonic-environment")
if os.path.isfile(SONIC_ENV_TEMPLATE_FILE) and os.path.isfile(SONIC_VERSION_YML_FILE):
clicommon.run_command(
"{} -d -y {} -t {},{}".format(
SONIC_CFGGEN_PATH,
SONIC_VERSION_YML_FILE,
SONIC_ENV_TEMPLATE_FILE,
SONIC_ENV_FILE
),
display_cmd=True
)
def cache_arp_entries():
success = True
cache_dir = '/host/config-reload'
click.echo('Caching ARP table to {}'.format(cache_dir))
if not os.path.exists(cache_dir):
os.mkdir(cache_dir)
arp_cache_cmd = '/usr/local/bin/fast-reboot-dump.py -t {}'.format(cache_dir)
cache_proc = subprocess.Popen(arp_cache_cmd, shell=True, text=True, stdout=subprocess.PIPE)
_, cache_err = cache_proc.communicate()
if cache_err:
click.echo("Could not cache ARP and FDB info prior to reloading")
success = False
if not cache_err:
fdb_cache_file = os.path.join(cache_dir, 'fdb.json')
arp_cache_file = os.path.join(cache_dir, 'arp.json')
fdb_filter_cmd = '/usr/local/bin/filter_fdb_entries -f {} -a {} -c /etc/sonic/configdb.json'.format(fdb_cache_file, arp_cache_file)
filter_proc = subprocess.Popen(fdb_filter_cmd, shell=True, text=True, stdout=subprocess.PIPE)
_, filter_err = filter_proc.communicate()
if filter_err:
click.echo("Could not filter FDB entries prior to reloading")
success = False
# If we are able to successfully cache ARP table info, signal SWSS to restore from our cache
# by creating /host/config-reload/needs-restore
if success:
restore_flag_file = os.path.join(cache_dir, 'needs-restore')
open(restore_flag_file, 'w').close()
return success
def remove_router_interface_ip_address(config_db, interface_name, ipaddress_to_remove):
table_name = get_interface_table_name(interface_name)
keys = config_db.get_keys(table_name)
for key in keys:
if not isinstance(key, tuple) or len(key) != 2:
continue
iface, ipaddress_string = key
if iface != interface_name:
continue
if ipaddress.ip_interface(ipaddress_string) == ipaddress_to_remove:
config_db.set_entry(table_name, (interface_name, ipaddress_string), None)
def validate_ipv4_address(ctx, param, ip_addr):
"""Helper function to validate ipv4 address
"""
try:
ip_n = ipaddress.ip_network(ip_addr, False)
if ip_n.version != 4:
raise click.UsageError("{} is not a valid IPv4 address".format(ip_addr))
return ip_addr
except ValueError as e:
raise click.UsageError(str(e))
def validate_gre_type(ctx, _, value):
"""A validator for validating input gre_type
"""
try:
base = 10
if value.lower().startswith('0x'):
base = 16
gre_type_value = int(value, base)
if gre_type_value < GRE_TYPE_RANGE.min or gre_type_value > GRE_TYPE_RANGE.max:
raise click.UsageError("{} is not a valid GRE type".format(value))
return gre_type_value
except ValueError:
raise click.UsageError("{} is not a valid GRE type".format(value))
# This is our main entrypoint - the main 'config' command
@click.group(cls=clicommon.AbbreviationGroup, context_settings=CONTEXT_SETTINGS)
@click.pass_context
def config(ctx):
"""SONiC command line - 'config' command"""
#
# Load asic_type for further use
#
global asic_type
try:
version_info = device_info.get_sonic_version_info()
if version_info:
asic_type = version_info['asic_type']
else:
asic_type = None
except (KeyError, TypeError) as e:
print("Caught an exception: " + str(e))
raise click.Abort()
# Load database config files
load_db_config()
if os.geteuid() != 0:
exit("Root privileges are required for this operation")
ctx.obj = Db()
# Add groups from other modules
config.add_command(aaa.aaa)
config.add_command(aaa.tacacs)
config.add_command(aaa.radius)
config.add_command(chassis_modules.chassis)
config.add_command(console.console)
config.add_command(feature.feature)
config.add_command(kdump.kdump)
config.add_command(kube.kubernetes)
config.add_command(muxcable.muxcable)
config.add_command(nat.nat)
config.add_command(vlan.vlan)
config.add_command(vxlan.vxlan)
#add mclag commands
config.add_command(mclag.mclag)
config.add_command(mclag.mclag_member)
config.add_command(mclag.mclag_unique_ip)
@config.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Existing files will be overwritten, continue?')
@click.argument('filename', required=False)
def save(filename):
"""Export current config DB to a file on disk.\n
<filename> : Names of configuration file(s) to save, separated by comma with no spaces in between
"""
num_asic = multi_asic.get_num_asics()
cfg_files = []
num_cfg_file = 1
if multi_asic.is_multi_asic():
num_cfg_file += num_asic
# If the user give the filename[s], extract the file names.
if filename is not None:
cfg_files = filename.split(',')
if len(cfg_files) != num_cfg_file:
click.echo("Input {} config file(s) separated by comma for multiple files ".format(num_cfg_file))
return
# In case of multi-asic mode we have additional config_db{NS}.json files for
# various namespaces created per ASIC. {NS} is the namespace index.
for inst in range(-1, num_cfg_file-1):
#inst = -1, refers to the linux host where there is no namespace.
if inst == -1:
namespace = None
else:
namespace = "{}{}".format(NAMESPACE_PREFIX, inst)
# Get the file from user input, else take the default file /etc/sonic/config_db{NS_id}.json
if cfg_files:
file = cfg_files[inst+1]
else:
if namespace is None:
file = DEFAULT_CONFIG_DB_FILE
else:
file = "/etc/sonic/config_db{}.json".format(inst)
if namespace is None:
command = "{} -d --print-data > {}".format(SONIC_CFGGEN_PATH, file)
else:
command = "{} -n {} -d --print-data > {}".format(SONIC_CFGGEN_PATH, namespace, file)
log.log_info("'save' executing...")
clicommon.run_command(command, display_cmd=True)
config_db = sort_dict(read_json_file(file))
with open(file, 'w') as config_db_file:
json.dump(config_db, config_db_file, indent=4)
@config.command()
@click.option('-y', '--yes', is_flag=True)
@click.argument('filename', required=False)
def load(filename, yes):
"""Import a previous saved config DB dump file.
<filename> : Names of configuration file(s) to load, separated by comma with no spaces in between
"""
if filename is None:
message = 'Load config from the default config file(s) ?'
else:
message = 'Load config from the file(s) {} ?'.format(filename)
if not yes:
click.confirm(message, abort=True)
num_asic = multi_asic.get_num_asics()
cfg_files = []
num_cfg_file = 1
if multi_asic.is_multi_asic():
num_cfg_file += num_asic
# If the user give the filename[s], extract the file names.
if filename is not None:
cfg_files = filename.split(',')
if len(cfg_files) != num_cfg_file:
click.echo("Input {} config file(s) separated by comma for multiple files ".format(num_cfg_file))
return
# In case of multi-asic mode we have additional config_db{NS}.json files for
# various namespaces created per ASIC. {NS} is the namespace index.
for inst in range(-1, num_cfg_file-1):
#inst = -1, refers to the linux host where there is no namespace.
if inst == -1:
namespace = None
else:
namespace = "{}{}".format(NAMESPACE_PREFIX, inst)
# Get the file from user input, else take the default file /etc/sonic/config_db{NS_id}.json
if cfg_files:
file = cfg_files[inst+1]
else:
if namespace is None:
file = DEFAULT_CONFIG_DB_FILE
else:
file = "/etc/sonic/config_db{}.json".format(inst)
# if any of the config files in linux host OR namespace is not present, return
if not os.path.exists(file):
click.echo("The config_db file {} doesn't exist".format(file))
return
if namespace is None:
command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, file)
else:
command = "{} -n {} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, namespace, file)
log.log_info("'load' executing...")
clicommon.run_command(command, display_cmd=True)
def print_dry_run_message(dry_run):
if dry_run:
click.secho("** DRY RUN EXECUTION **", fg="yellow", underline=True)
@config.command('apply-patch')
@click.argument('patch-file-path', type=str, required=True)
@click.option('-f', '--format', type=click.Choice([e.name for e in ConfigFormat]),
default=ConfigFormat.CONFIGDB.name,
help='format of config of the patch is either ConfigDb(ABNF) or SonicYang',
show_default=True)
@click.option('-d', '--dry-run', is_flag=True, default=False, help='test out the command without affecting config state')
@click.option('-n', '--ignore-non-yang-tables', is_flag=True, default=False, help='ignore validation for tables without YANG models', hidden=True)
@click.option('-i', '--ignore-path', multiple=True, help='ignore validation for config specified by given path which is a JsonPointer', hidden=True)
@click.option('-v', '--verbose', is_flag=True, default=False, help='print additional details of what the operation is doing')
@click.pass_context
def apply_patch(ctx, patch_file_path, format, dry_run, ignore_non_yang_tables, ignore_path, verbose):
"""Apply given patch of updates to Config. A patch is a JsonPatch which follows rfc6902.
This command can be used do partial updates to the config with minimum disruption to running processes.
It allows addition as well as deletion of configs. The patch file represents a diff of ConfigDb(ABNF)
format or SonicYang format.
<patch-file-path>: Path to the patch file on the file-system."""
try:
print_dry_run_message(dry_run)
with open(patch_file_path, 'r') as fh:
text = fh.read()
patch_as_json = json.loads(text)
patch = jsonpatch.JsonPatch(patch_as_json)
config_format = ConfigFormat[format.upper()]
GenericUpdater().apply_patch(patch, config_format, verbose, dry_run, ignore_non_yang_tables, ignore_path)
click.secho("Patch applied successfully.", fg="cyan", underline=True)
except Exception as ex:
click.secho("Failed to apply patch", fg="red", underline=True, err=True)
ctx.fail(ex)
@config.command()
@click.argument('target-file-path', type=str, required=True)
@click.option('-f', '--format', type=click.Choice([e.name for e in ConfigFormat]),
default=ConfigFormat.CONFIGDB.name,
help='format of target config is either ConfigDb(ABNF) or SonicYang',
show_default=True)
@click.option('-d', '--dry-run', is_flag=True, default=False, help='test out the command without affecting config state')
@click.option('-n', '--ignore-non-yang-tables', is_flag=True, default=False, help='ignore validation for tables without YANG models', hidden=True)
@click.option('-i', '--ignore-path', multiple=True, help='ignore validation for config specified by given path which is a JsonPointer', hidden=True)
@click.option('-v', '--verbose', is_flag=True, default=False, help='print additional details of what the operation is doing')
@click.pass_context
def replace(ctx, target_file_path, format, dry_run, ignore_non_yang_tables, ignore_path, verbose):
"""Replace the whole config with the specified config. The config is replaced with minimum disruption e.g.
if ACL config is different between current and target config only ACL config is updated, and other config/services
such as DHCP will not be affected.
**WARNING** The target config file should be the whole config, not just the part intended to be updated.
<target-file-path>: Path to the target file on the file-system."""
try:
print_dry_run_message(dry_run)
with open(target_file_path, 'r') as fh:
target_config_as_text = fh.read()
target_config = json.loads(target_config_as_text)
config_format = ConfigFormat[format.upper()]
GenericUpdater().replace(target_config, config_format, verbose, dry_run, ignore_non_yang_tables, ignore_path)
click.secho("Config replaced successfully.", fg="cyan", underline=True)
except Exception as ex:
click.secho("Failed to replace config", fg="red", underline=True, err=True)
ctx.fail(ex)
@config.command()
@click.argument('checkpoint-name', type=str, required=True)
@click.option('-d', '--dry-run', is_flag=True, default=False, help='test out the command without affecting config state')
@click.option('-n', '--ignore-non-yang-tables', is_flag=True, default=False, help='ignore validation for tables without YANG models', hidden=True)
@click.option('-i', '--ignore-path', multiple=True, help='ignore validation for config specified by given path which is a JsonPointer', hidden=True)
@click.option('-v', '--verbose', is_flag=True, default=False, help='print additional details of what the operation is doing')
@click.pass_context
def rollback(ctx, checkpoint_name, dry_run, ignore_non_yang_tables, ignore_path, verbose):
"""Rollback the whole config to the specified checkpoint. The config is rolled back with minimum disruption e.g.
if ACL config is different between current and checkpoint config only ACL config is updated, and other config/services
such as DHCP will not be affected.
<checkpoint-name>: The checkpoint name, use `config list-checkpoints` command to see available checkpoints."""
try:
print_dry_run_message(dry_run)
GenericUpdater().rollback(checkpoint_name, verbose, dry_run, ignore_non_yang_tables, ignore_path)
click.secho("Config rolled back successfully.", fg="cyan", underline=True)
except Exception as ex:
click.secho("Failed to rollback config", fg="red", underline=True, err=True)
ctx.fail(ex)
@config.command()
@click.argument('checkpoint-name', type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, default=False, help='print additional details of what the operation is doing')
@click.pass_context
def checkpoint(ctx, checkpoint_name, verbose):
"""Take a checkpoint of the whole current config with the specified checkpoint name.
<checkpoint-name>: The checkpoint name, use `config list-checkpoints` command to see available checkpoints."""
try:
GenericUpdater().checkpoint(checkpoint_name, verbose)
click.secho("Checkpoint created successfully.", fg="cyan", underline=True)
except Exception as ex:
click.secho("Failed to create a config checkpoint", fg="red", underline=True, err=True)
ctx.fail(ex)
@config.command('delete-checkpoint')
@click.argument('checkpoint-name', type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, default=False, help='print additional details of what the operation is doing')
@click.pass_context
def delete_checkpoint(ctx, checkpoint_name, verbose):
"""Delete a checkpoint with the specified checkpoint name.
<checkpoint-name>: The checkpoint name, use `config list-checkpoints` command to see available checkpoints."""
try:
GenericUpdater().delete_checkpoint(checkpoint_name, verbose)
click.secho("Checkpoint deleted successfully.", fg="cyan", underline=True)
except Exception as ex:
click.secho("Failed to delete config checkpoint", fg="red", underline=True, err=True)
ctx.fail(ex)
@config.command('list-checkpoints')
@click.option('-v', '--verbose', is_flag=True, default=False, help='print additional details of what the operation is doing')
@click.pass_context
def list_checkpoints(ctx, verbose):
"""List the config checkpoints available."""
try:
checkpoints_list = GenericUpdater().list_checkpoints(verbose)
formatted_output = json.dumps(checkpoints_list, indent=4)
click.echo(formatted_output)
except Exception as ex:
click.secho("Failed to list config checkpoints", fg="red", underline=True, err=True)
ctx.fail(ex)
@config.command()
@click.option('-y', '--yes', is_flag=True)
@click.option('-l', '--load-sysinfo', is_flag=True, help='load system default information (mac, portmap etc) first.')
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
@click.option('-d', '--disable_arp_cache', default=False, is_flag=True, help='Do not cache ARP table before reloading (applies to dual ToR systems only)')
@click.option('-f', '--force', default=False, is_flag=True, help='Force config reload without system checks')
@click.option('-t', '--file_format', default='config_db',type=click.Choice(['config_yang', 'config_db']),show_default=True,help='specify the file format')
@click.argument('filename', required=False)
@clicommon.pass_db
def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cache, force, file_format):
"""Clear current configuration and import a previous saved config DB dump file.
<filename> : Names of configuration file(s) to load, separated by comma with no spaces in between
"""
if not force and not no_service_restart:
if _is_system_starting():
click.echo("System is not up. Retry later or use -f to avoid system checks")
return
if not _delay_timers_elapsed():
click.echo("Relevant services are not up. Retry later or use -f to avoid system checks")
return
if not _swss_ready():
click.echo("SwSS container is not ready. Retry later or use -f to avoid system checks")
return
if filename is None:
message = 'Clear current config and reload config in {} format from the default config file(s) ?'.format(file_format)
else:
message = 'Clear current config and reload config in {} from the file(s) {} ?'.format(file_format, filename)
if not yes:
click.confirm(message, abort=True)
log.log_info("'reload' executing...")
num_asic = multi_asic.get_num_asics()
cfg_files = []
num_cfg_file = 1
# single config_yang file for the multi asic device
if multi_asic.is_multi_asic() and file_format == 'config_db':
num_cfg_file += num_asic
# Remove cached PG drop counters data
dropstat_dir_prefix = '/tmp/dropstat'
command = "rm -rf {}-*".format(dropstat_dir_prefix)
clicommon.run_command(command, display_cmd=True)
# If the user give the filename[s], extract the file names.
if filename is not None:
cfg_files = filename.split(',')
if len(cfg_files) != num_cfg_file:
click.echo("Input {} config file(s) separated by comma for multiple files ".format(num_cfg_file))
return
# For dual ToR devices, cache ARP and FDB info
localhost_metadata = db.cfgdb.get_table('DEVICE_METADATA')['localhost']
cache_arp_table = not disable_arp_cache and 'subtype' in localhost_metadata and localhost_metadata['subtype'].lower() == 'dualtor'
if cache_arp_table:
cache_arp_entries()
#Stop services before config push
if not no_service_restart:
log.log_info("'reload' stopping services...")
_stop_services()
# In Single ASIC platforms we have single DB service. In multi-ASIC platforms we have a global DB
# service running in the host + DB services running in each ASIC namespace created per ASIC.
# In the below logic, we get all namespaces in this platform and add an empty namespace ''
# denoting the current namespace which we are in ( the linux host )
for inst in range(-1, num_cfg_file-1):
# Get the namespace name, for linux host it is None
if inst == -1:
namespace = None
else:
namespace = "{}{}".format(NAMESPACE_PREFIX, inst)
# Get the file from user input, else take the default file /etc/sonic/config_db{NS_id}.json
if cfg_files:
file = cfg_files[inst+1]
else:
if file_format == 'config_db':
if namespace is None:
file = DEFAULT_CONFIG_DB_FILE
else:
file = "/etc/sonic/config_db{}.json".format(inst)
else:
file = DEFAULT_CONFIG_YANG_FILE
# Check the file exists before proceeding.
if not os.path.exists(file):
click.echo("The config file {} doesn't exist".format(file))
continue
if load_sysinfo:
try:
command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file)
proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE)
output, err = proc.communicate()
except FileNotFoundError as e:
click.echo("{}".format(str(e)), err=True)
raise click.Abort()
except Exception as e:
click.echo("{}\n{}".format(type(e), str(e)), err=True)
raise click.Abort()
if not output:
click.secho("Could not get the HWSKU from config file, Exiting!!!", fg='magenta')
sys.exit(1)
cfg_hwsku = output.strip()
if namespace is None:
config_db = ConfigDBConnector()
else:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
client = config_db.get_redis_client(config_db.CONFIG_DB)
client.flushdb()
if load_sysinfo:
if namespace is None:
command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku)
else:
command = "{} -H -k {} -n {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku, namespace)
clicommon.run_command(command, display_cmd=True)
# For the database service running in linux host we use the file user gives as input
# or by default DEFAULT_CONFIG_DB_FILE. In the case of database service running in namespace,
# the default config_db<namespaceID>.json format is used.
config_gen_opts = ""
if os.path.isfile(INIT_CFG_FILE):
config_gen_opts += " -j {} ".format(INIT_CFG_FILE)
if file_format == 'config_db':
config_gen_opts += ' -j {} '.format(file)
else:
config_gen_opts += ' -Y {} '.format(file)
if namespace is not None:
config_gen_opts += " -n {} ".format(namespace)
command = "{sonic_cfggen} {options} --write-to-db".format(
sonic_cfggen=SONIC_CFGGEN_PATH,
options=config_gen_opts)
clicommon.run_command(command, display_cmd=True)
client.set(config_db.INIT_INDICATOR, 1)
# Migrate DB contents to latest version
db_migrator='/usr/local/bin/db_migrator.py'
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
if namespace is None:
command = "{} -o migrate".format(db_migrator)
else:
command = "{} -o migrate -n {}".format(db_migrator, namespace)
clicommon.run_command(command, display_cmd=True)
# Re-generate the environment variable in case config_db.json was edited
update_sonic_environment()
# We first run "systemctl reset-failed" to remove the "failed"
# status from all services before we attempt to restart them
if not no_service_restart:
_reset_failed_services()
log.log_info("'reload' restarting services...")
_restart_services()
@config.command("load_mgmt_config")
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Reload mgmt config?')
@click.argument('filename', default='/etc/sonic/device_desc.xml', type=click.Path(exists=True))
def load_mgmt_config(filename):
"""Reconfigure hostname and mgmt interface based on device description file."""
log.log_info("'load_mgmt_config' executing...")
command = "{} -M {} --write-to-db".format(SONIC_CFGGEN_PATH, filename)
clicommon.run_command(command, display_cmd=True)
#FIXME: After config DB daemon for hostname and mgmt interface is implemented, we'll no longer need to do manual configuration here
config_data = parse_device_desc_xml(filename)
hostname = config_data['DEVICE_METADATA']['localhost']['hostname']
_change_hostname(hostname)
mgmt_conf = netaddr.IPNetwork(list(config_data['MGMT_INTERFACE'].keys())[0][1])
gw_addr = list(config_data['MGMT_INTERFACE'].values())[0]['gwaddr']
command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask))
clicommon.run_command(command, display_cmd=True)
command = "ip route add default via {} dev eth0 table default".format(gw_addr)
clicommon.run_command(command, display_cmd=True, ignore_error=True)
command = "ip rule add from {} table default".format(str(mgmt_conf.ip))
clicommon.run_command(command, display_cmd=True, ignore_error=True)
command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
clicommon.run_command(command, display_cmd=True, ignore_error=True)
click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")
@config.command("load_minigraph")
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Reload config from minigraph?')
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
@clicommon.pass_db
def load_minigraph(db, no_service_restart):
"""Reconfigure based on minigraph."""
log.log_info("'load_minigraph' executing...")
#Stop services before config push
if not no_service_restart:
log.log_info("'load_minigraph' stopping services...")
_stop_services()
# For Single Asic platform the namespace list has the empty string
# for mulit Asic platform the empty string to generate the config
# for host
namespace_list = [DEFAULT_NAMESPACE]
num_npus = multi_asic.get_num_asics()
if num_npus > 1:
namespace_list += multi_asic.get_namespaces_from_linux()
for namespace in namespace_list:
if namespace is DEFAULT_NAMESPACE:
config_db = ConfigDBConnector()
cfggen_namespace_option = " "
ns_cmd_prefix = ""
else:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
cfggen_namespace_option = " -n {}".format(namespace)
ns_cmd_prefix = "sudo ip netns exec {} ".format(namespace)
config_db.connect()
client = config_db.get_redis_client(config_db.CONFIG_DB)
client.flushdb()
if os.path.isfile('/etc/sonic/init_cfg.json'):
command = "{} -H -m -j /etc/sonic/init_cfg.json {} --write-to-db".format(SONIC_CFGGEN_PATH, cfggen_namespace_option)
else:
command = "{} -H -m --write-to-db {}".format(SONIC_CFGGEN_PATH, cfggen_namespace_option)
clicommon.run_command(command, display_cmd=True)
client.set(config_db.INIT_INDICATOR, 1)
# Update SONiC environmnet file
update_sonic_environment()
if os.path.isfile('/etc/sonic/acl.json'):
clicommon.run_command("acl-loader update full /etc/sonic/acl.json", display_cmd=True)
# Load port_config.json
try:
load_port_config(db.cfgdb, '/etc/sonic/port_config.json')
except Exception as e:
click.secho("Failed to load port_config.json, Error: {}".format(str(e)), fg='magenta')
# generate QoS and Buffer configs
clicommon.run_command("config qos reload --no-dynamic-buffer", display_cmd=True)
# get the device type
device_type = _get_device_type()
if device_type != 'MgmtToRRouter' and device_type != 'MgmtTsToR' and device_type != 'EPMS':
clicommon.run_command("pfcwd start_default", display_cmd=True)
# Write latest db version string into db
db_migrator='/usr/local/bin/db_migrator.py'
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
for namespace in namespace_list:
if namespace is DEFAULT_NAMESPACE:
cfggen_namespace_option = " "
else:
cfggen_namespace_option = " -n {}".format(namespace)
clicommon.run_command(db_migrator + ' -o set_version' + cfggen_namespace_option)
# We first run "systemctl reset-failed" to remove the "failed"
# status from all services before we attempt to restart them
if not no_service_restart:
_reset_failed_services()
#FIXME: After config DB daemon is implemented, we'll no longer need to restart every service.
log.log_info("'load_minigraph' restarting services...")
_restart_services()
click.echo("Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`.")
def load_port_config(config_db, port_config_path):
if not os.path.isfile(port_config_path):
return
try:
# Load port_config.json
port_config_input = read_json_file(port_config_path)
except Exception:
raise Exception("Bad format: json file broken")
# Validate if the input is an array
if not isinstance(port_config_input, list):
raise Exception("Bad format: port_config is not an array")
if len(port_config_input) == 0 or 'PORT' not in port_config_input[0]:
raise Exception("Bad format: PORT table not exists")
port_config = port_config_input[0]['PORT']
# Ensure all ports are exist
port_table = {}
for port_name in port_config.keys():
port_entry = config_db.get_entry('PORT', port_name)
if not port_entry:
raise Exception("Port {} is not defined in current device".format(port_name))
port_table[port_name] = port_entry
# Update port state
for port_name in port_config.keys():
if 'admin_status' not in port_config[port_name]:
continue
if 'admin_status' in port_table[port_name]:
if port_table[port_name]['admin_status'] == port_config[port_name]['admin_status']:
continue
clicommon.run_command('config interface {} {}'.format(
'startup' if port_config[port_name]['admin_status'] == 'up' else 'shutdown',
port_name), display_cmd=True)
return
#
# 'hostname' command
#
@config.command('hostname')
@click.argument('new_hostname', metavar='<new_hostname>', required=True)
def hostname(new_hostname):
"""Change device hostname without impacting the traffic."""
config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"hostname" : new_hostname})
try:
command = "service hostname-config restart"
clicommon.run_command(command, display_cmd=True)
except SystemExit as e:
click.echo("Restarting hostname-config service failed with error {}".format(e))
raise
# Reload Monit configuration to pick up new hostname in case it changed
click.echo("Reloading Monit configuration ...")
clicommon.run_command("sudo monit reload")
click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")
#
# 'synchronous_mode' command ('config synchronous_mode ...')
#
@config.command('synchronous_mode')
@click.argument('sync_mode', metavar='<enable|disable>', required=True)
def synchronous_mode(sync_mode):
""" Enable or disable synchronous mode between orchagent and syncd \n
swss restart required to apply the configuration \n
Options to restart swss and apply the configuration: \n
1. config save -y \n
config reload -y \n
2. systemctl restart swss
"""
if sync_mode == 'enable' or sync_mode == 'disable':
config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"synchronous_mode" : sync_mode})
click.echo("""Wrote %s synchronous mode into CONFIG_DB, swss restart required to apply the configuration: \n
Option 1. config save -y \n
config reload -y \n
Option 2. systemctl restart swss""" % sync_mode)
else:
raise click.BadParameter("Error: Invalid argument %s, expect either enable or disable" % sync_mode)
#
# 'portchannel' group ('config portchannel ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
# TODO add "hidden=True if this is a single ASIC platform, once we have click 7.0 in all branches.
@click.option('-n', '--namespace', help='Namespace name',
required=True if multi_asic.is_multi_asic() else False, type=click.Choice(multi_asic.get_namespace_list()))
@click.pass_context
def portchannel(ctx, namespace):
# Set namespace to default_namespace if it is None.
if namespace is None:
namespace = DEFAULT_NAMESPACE
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=str(namespace))
config_db.connect()
ctx.obj = {'db': config_db, 'namespace': str(namespace)}
@portchannel.command('add')
@click.argument('portchannel_name', metavar='<portchannel_name>', required=True)
@click.option('--min-links', default=1, type=click.IntRange(1,1024))
@click.option('--fallback', default='false')
@click.pass_context
def add_portchannel(ctx, portchannel_name, min_links, fallback):
"""Add port channel"""
if is_portchannel_name_valid(portchannel_name) != True:
ctx.fail("{} is invalid!, name should have prefix '{}' and suffix '{}'"
.format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO))
db = ctx.obj['db']
if is_portchannel_present_in_db(db, portchannel_name):
ctx.fail("{} already exists!".format(portchannel_name))
fvs = {'admin_status': 'up',
'mtu': '9100',
'lacp_key': 'auto'}
if min_links != 0:
fvs['min_links'] = str(min_links)
if fallback != 'false':
fvs['fallback'] = 'true'
db.set_entry('PORTCHANNEL', portchannel_name, fvs)
@portchannel.command('del')
@click.argument('portchannel_name', metavar='<portchannel_name>', required=True)
@click.pass_context
def remove_portchannel(ctx, portchannel_name):
"""Remove port channel"""
if is_portchannel_name_valid(portchannel_name) != True:
ctx.fail("{} is invalid!, name should have prefix '{}' and suffix '{}'"
.format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO))
db = ctx.obj['db']
# Dont proceed if the port channel does not exist
if is_portchannel_present_in_db(db, portchannel_name) is False:
ctx.fail("{} is not present.".format(portchannel_name))
if len([(k, v) for k, v in db.get_table('PORTCHANNEL_MEMBER') if k == portchannel_name]) != 0:
click.echo("Error: Portchannel {} contains members. Remove members before deleting Portchannel!".format(portchannel_name))
else:
db.set_entry('PORTCHANNEL', portchannel_name, None)
@portchannel.group(cls=clicommon.AbbreviationGroup, name='member')
@click.pass_context
def portchannel_member(ctx):
pass
@portchannel_member.command('add')
@click.argument('portchannel_name', metavar='<portchannel_name>', required=True)
@click.argument('port_name', metavar='<port_name>', required=True)
@click.pass_context
def add_portchannel_member(ctx, portchannel_name, port_name):
"""Add member to port channel"""
db = ctx.obj['db']
if clicommon.is_port_mirror_dst_port(db, port_name):
ctx.fail("{} is configured as mirror destination port".format(port_name))
# Check if the member interface given by user is valid in the namespace.
if port_name.startswith("Ethernet") is False or interface_name_is_valid(db, port_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
# Dont proceed if the port channel name is not valid
if is_portchannel_name_valid(portchannel_name) is False:
ctx.fail("{} is invalid!, name should have prefix '{}' and suffix '{}'"
.format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO))
# Dont proceed if the port channel does not exist
if is_portchannel_present_in_db(db, portchannel_name) is False:
ctx.fail("{} is not present.".format(portchannel_name))
# Dont allow a port to be member of port channel if it is configured with an IP address
for key,value in db.get_table('INTERFACE').items():
if type(key) == tuple:
continue
if key == port_name:
ctx.fail(" {} has ip address configured".format(port_name))
return
# Dont allow a port to be member of port channel if it is configured as a VLAN member
for k,v in db.get_table('VLAN_MEMBER'):
if v == port_name:
ctx.fail("%s Interface configured as VLAN_MEMBER under vlan : %s" %(port_name,str(k)))
return
# Dont allow a port to be member of port channel if it is already member of a port channel
for k,v in db.get_table('PORTCHANNEL_MEMBER'):
if v == port_name:
ctx.fail("{} Interface is already member of {} ".format(v,k))
# Dont allow a port to be member of port channel if its speed does not match with existing members
for k,v in db.get_table('PORTCHANNEL_MEMBER'):
if k == portchannel_name:
member_port_entry = db.get_entry('PORT', v)
port_entry = db.get_entry('PORT', port_name)
if member_port_entry is not None and port_entry is not None:
member_port_speed = member_port_entry.get(PORT_SPEED)
port_speed = port_entry.get(PORT_SPEED)
if member_port_speed != port_speed:
ctx.fail("Port speed of {} is different than the other members of the portchannel {}"
.format(port_name, portchannel_name))
# Dont allow a port to be member of port channel if its MTU does not match with portchannel
portchannel_entry = db.get_entry('PORTCHANNEL', portchannel_name)
if portchannel_entry and portchannel_entry.get(PORT_MTU) is not None :
port_entry = db.get_entry('PORT', port_name)
if port_entry and port_entry.get(PORT_MTU) is not None:
port_mtu = port_entry.get(PORT_MTU)
portchannel_mtu = portchannel_entry.get(PORT_MTU)
if portchannel_mtu != port_mtu:
ctx.fail("Port MTU of {} is different than the {} MTU size"
.format(port_name, portchannel_name))
# Dont allow a port to be member of port channel if its TPID is not at default 0x8100
# If TPID is supported at LAG level, when member is added, the LAG's TPID is applied to the
# new member by SAI.
port_entry = db.get_entry('PORT', port_name)
if port_entry and port_entry.get(PORT_TPID) is not None:
port_tpid = port_entry.get(PORT_TPID)
if port_tpid != DEFAULT_TPID:
ctx.fail("Port TPID of {}: {} is not at default 0x8100".format(port_name, port_tpid))
db.set_entry('PORTCHANNEL_MEMBER', (portchannel_name, port_name),
{'NULL': 'NULL'})
@portchannel_member.command('del')
@click.argument('portchannel_name', metavar='<portchannel_name>', required=True)
@click.argument('port_name', metavar='<port_name>', required=True)
@click.pass_context
def del_portchannel_member(ctx, portchannel_name, port_name):
"""Remove member from portchannel"""
# Dont proceed if the port channel name is not valid
if is_portchannel_name_valid(portchannel_name) is False:
ctx.fail("{} is invalid!, name should have prefix '{}' and suffix '{}'"
.format(portchannel_name, CFG_PORTCHANNEL_PREFIX, CFG_PORTCHANNEL_NO))
db = ctx.obj['db']
# Check if the member interface given by user is valid in the namespace.
if interface_name_is_valid(db, port_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
# Dont proceed if the port channel does not exist
if is_portchannel_present_in_db(db, portchannel_name) is False:
ctx.fail("{} is not present.".format(portchannel_name))
# Dont proceed if the the port is not an existing member of the port channel
if not is_port_member_of_this_portchannel(db, port_name, portchannel_name):
ctx.fail("{} is not a member of portchannel {}".format(port_name, portchannel_name))
db.set_entry('PORTCHANNEL_MEMBER', (portchannel_name, port_name), None)
db.set_entry('PORTCHANNEL_MEMBER', portchannel_name + '|' + port_name, None)
#
# 'mirror_session' group ('config mirror_session ...')
#
@config.group(cls=clicommon.AbbreviationGroup, name='mirror_session')
def mirror_session():
pass
#
# 'add' subgroup ('config mirror_session add ...')
#
@mirror_session.command('add')
@click.argument('session_name', metavar='<session_name>', required=True)
@click.argument('src_ip', metavar='<src_ip>', callback=validate_ipv4_address, required=True)
@click.argument('dst_ip', metavar='<dst_ip>', callback=validate_ipv4_address, required=True)
@click.argument('dscp', metavar='<dscp>', type=DSCP_RANGE, required=True)
@click.argument('ttl', metavar='<ttl>', type=TTL_RANGE, required=True)
@click.argument('gre_type', metavar='[gre_type]', callback=validate_gre_type, required=False)
@click.argument('queue', metavar='[queue]', type=QUEUE_RANGE, required=False)
@click.option('--policer')
def add(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer):
""" Add ERSPAN mirror session.(Legacy support) """
add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer)
@mirror_session.group(cls=clicommon.AbbreviationGroup, name='erspan')
@click.pass_context
def erspan(ctx):
""" ERSPAN mirror_session """
pass
#
# 'add' subcommand
#
@erspan.command('add')
@click.argument('session_name', metavar='<session_name>', required=True)
@click.argument('src_ip', metavar='<src_ip>', callback=validate_ipv4_address, required=True)
@click.argument('dst_ip', metavar='<dst_ip>', callback=validate_ipv4_address,required=True)
@click.argument('dscp', metavar='<dscp>', type=DSCP_RANGE, required=True)
@click.argument('ttl', metavar='<ttl>', type=TTL_RANGE, required=True)
@click.argument('gre_type', metavar='[gre_type]', callback=validate_gre_type, required=False)
@click.argument('queue', metavar='[queue]', type=QUEUE_RANGE, required=False)
@click.argument('src_port', metavar='[src_port]', required=False)
@click.argument('direction', metavar='[direction]', required=False)
@click.option('--policer')
def add(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer, src_port, direction):
""" Add ERSPAN mirror session """
add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer, src_port, direction)
def gather_session_info(session_info, policer, queue, src_port, direction):
if policer:
session_info['policer'] = policer
if queue:
session_info['queue'] = queue
if src_port:
if clicommon.get_interface_naming_mode() == "alias":
src_port_list = []
for port in src_port.split(","):
src_port_list.append(interface_alias_to_name(None, port))
src_port=",".join(src_port_list)
session_info['src_port'] = src_port
if not direction:
direction = "both"
session_info['direction'] = direction.upper()
return session_info
def add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer, src_port=None, direction=None):
session_info = {
"type" : "ERSPAN",
"src_ip": src_ip,
"dst_ip": dst_ip,
"dscp": dscp,
"ttl": ttl
}
if gre_type:
session_info['gre_type'] = gre_type
session_info = gather_session_info(session_info, policer, queue, src_port, direction)
"""
For multi-npu platforms we need to program all front asic namespaces
"""
namespaces = multi_asic.get_all_namespaces()
if not namespaces['front_ns']:
config_db = ConfigDBConnector()
config_db.connect()
if validate_mirror_session_config(config_db, session_name, None, src_port, direction) is False:
return
config_db.set_entry("MIRROR_SESSION", session_name, session_info)
else:
per_npu_configdb = {}
for front_asic_namespaces in namespaces['front_ns']:
per_npu_configdb[front_asic_namespaces] = ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespaces)
per_npu_configdb[front_asic_namespaces].connect()
if validate_mirror_session_config(per_npu_configdb[front_asic_namespaces], session_name, None, src_port, direction) is False:
return
per_npu_configdb[front_asic_namespaces].set_entry("MIRROR_SESSION", session_name, session_info)
@mirror_session.group(cls=clicommon.AbbreviationGroup, name='span')
@click.pass_context
def span(ctx):
""" SPAN mirror session """
pass
@span.command('add')
@click.argument('session_name', metavar='<session_name>', required=True)
@click.argument('dst_port', metavar='<dst_port>', required=True)
@click.argument('src_port', metavar='[src_port]', required=False)
@click.argument('direction', metavar='[direction]', required=False)
@click.argument('queue', metavar='[queue]', type=QUEUE_RANGE, required=False)
@click.option('--policer')
def add(session_name, dst_port, src_port, direction, queue, policer):
""" Add SPAN mirror session """
add_span(session_name, dst_port, src_port, direction, queue, policer)
def add_span(session_name, dst_port, src_port, direction, queue, policer):
if clicommon.get_interface_naming_mode() == "alias":
dst_port = interface_alias_to_name(None, dst_port)
if dst_port is None:
click.echo("Error: Destination Interface {} is invalid".format(dst_port))
return
session_info = {
"type" : "SPAN",
"dst_port": dst_port,
}
session_info = gather_session_info(session_info, policer, queue, src_port, direction)
"""
For multi-npu platforms we need to program all front asic namespaces
"""
namespaces = multi_asic.get_all_namespaces()
if not namespaces['front_ns']:
config_db = ConfigDBConnector()
config_db.connect()
if validate_mirror_session_config(config_db, session_name, dst_port, src_port, direction) is False:
return
config_db.set_entry("MIRROR_SESSION", session_name, session_info)
else:
per_npu_configdb = {}
for front_asic_namespaces in namespaces['front_ns']:
per_npu_configdb[front_asic_namespaces] = ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespaces)
per_npu_configdb[front_asic_namespaces].connect()
if validate_mirror_session_config(per_npu_configdb[front_asic_namespaces], session_name, dst_port, src_port, direction) is False:
return
per_npu_configdb[front_asic_namespaces].set_entry("MIRROR_SESSION", session_name, session_info)
@mirror_session.command()
@click.argument('session_name', metavar='<session_name>', required=True)
def remove(session_name):
""" Delete mirror session """
"""
For multi-npu platforms we need to program all front asic namespaces
"""
namespaces = multi_asic.get_all_namespaces()
if not namespaces['front_ns']:
config_db = ConfigDBConnector()
config_db.connect()
config_db.set_entry("MIRROR_SESSION", session_name, None)
else:
per_npu_configdb = {}
for front_asic_namespaces in namespaces['front_ns']:
per_npu_configdb[front_asic_namespaces] = ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespaces)
per_npu_configdb[front_asic_namespaces].connect()
per_npu_configdb[front_asic_namespaces].set_entry("MIRROR_SESSION", session_name, None)
#
# 'pfcwd' group ('config pfcwd ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
def pfcwd():
"""Configure pfc watchdog """
pass
@pfcwd.command()
@click.option('--action', '-a', type=click.Choice(['drop', 'forward', 'alert']))
@click.option('--restoration-time', '-r', type=click.IntRange(100, 60000))
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.argument('ports', nargs=-1)
@click.argument('detection-time', type=click.IntRange(100, 5000))
def start(action, restoration_time, ports, detection_time, verbose):
"""
Start PFC watchdog on port(s). To config all ports, use all as input.
Example:
config pfcwd start --action drop all 400 --restoration-time 400
"""
cmd = "pfcwd start"
if action:
cmd += " --action {}".format(action)
if ports:
ports = set(ports) - set(['ports', 'detection-time'])
cmd += " {}".format(' '.join(ports))
if detection_time:
cmd += " {}".format(detection_time)
if restoration_time:
cmd += " --restoration-time {}".format(restoration_time)
clicommon.run_command(cmd, display_cmd=verbose)
@pfcwd.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def stop(verbose):
""" Stop PFC watchdog """
cmd = "pfcwd stop"
clicommon.run_command(cmd, display_cmd=verbose)
@pfcwd.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.argument('poll_interval', type=click.IntRange(100, 3000))
def interval(poll_interval, verbose):
""" Set PFC watchdog counter polling interval (ms) """
cmd = "pfcwd interval {}".format(poll_interval)
clicommon.run_command(cmd, display_cmd=verbose)
@pfcwd.command('counter_poll')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.argument('counter_poll', type=click.Choice(['enable', 'disable']))
def counter_poll(counter_poll, verbose):
""" Enable/disable counter polling """
cmd = "pfcwd counter_poll {}".format(counter_poll)
clicommon.run_command(cmd, display_cmd=verbose)
@pfcwd.command('big_red_switch')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@click.argument('big_red_switch', type=click.Choice(['enable', 'disable']))
def big_red_switch(big_red_switch, verbose):
""" Enable/disable BIG_RED_SWITCH mode """
cmd = "pfcwd big_red_switch {}".format(big_red_switch)
clicommon.run_command(cmd, display_cmd=verbose)
@pfcwd.command('start_default')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def start_default(verbose):
""" Start PFC WD by default configurations """
cmd = "pfcwd start_default"
clicommon.run_command(cmd, display_cmd=verbose)
#
# 'cbf' group ('config cbf ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def cbf(ctx):
"""CBF-related configuration tasks"""
pass
@cbf.command('clear')
def clear():
"""Clear CBF configuration"""
log.log_info("'cbf clear' executing...")
_clear_cbf()
@cbf.command('reload')
@click.pass_context
@click.option(
'--json-data', type=click.STRING,
help="json string with additional data, valid with --dry-run option"
)
@click.option(
'--dry_run', type=click.STRING,
help="Dry run, writes config to the given file"
)
def reload(ctx, dry_run, json_data):
"""Reload CBF configuration"""
log.log_info("'cbf reload' executing...")
_clear_cbf()
_, hwsku_path = device_info.get_paths_to_platform_and_hwsku_dirs()
sonic_version_file = device_info.get_sonic_version_file()
from_db = "-d --write-to-db"
if dry_run:
from_db = "--additional-data \'{}\'".format(json_data) if json_data else ""
namespace_list = [DEFAULT_NAMESPACE]
if multi_asic.get_num_asics() > 1:
namespace_list = multi_asic.get_namespaces_from_linux()
for ns in namespace_list:
if ns is DEFAULT_NAMESPACE:
asic_id_suffix = ""
config_db = ConfigDBConnector()
else:
asic_id = multi_asic.get_asic_id_from_name(ns)
if asic_id is None:
click.secho(
"Command 'cbf reload' failed with invalid namespace '{}'".
format(ns),
fg="yellow"
)
raise click.Abort()
asic_id_suffix = str(asic_id)
config_db = ConfigDBConnector(
use_unix_socket_path=True, namespace=ns
)
config_db.connect()
cbf_template_file = os.path.join(hwsku_path, asic_id_suffix, "cbf.json.j2")
if os.path.isfile(cbf_template_file):
cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
fname = "{}{}".format(dry_run, asic_id_suffix) if dry_run else "config-db"
command = "{} {} {} -t {},{} -y {}".format(
SONIC_CFGGEN_PATH, cmd_ns, from_db,
cbf_template_file, fname, sonic_version_file
)
# Apply the configuration
clicommon.run_command(command, display_cmd=True)
else:
click.secho("CBF definition template not found at {}".format(
cbf_template_file
), fg="yellow")
#
# 'qos' group ('config qos ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def qos(ctx):
"""QoS-related configuration tasks"""
pass
@qos.command('clear')
def clear():
"""Clear QoS configuration"""
log.log_info("'qos clear' executing...")
_clear_qos()
def _update_buffer_calculation_model(config_db, model):
"""Update the buffer calculation model into CONFIG_DB"""
buffer_model_changed = False
device_metadata = config_db.get_entry('DEVICE_METADATA', 'localhost')
if device_metadata.get('buffer_model') != model:
buffer_model_changed = True
device_metadata['buffer_model'] = model
config_db.set_entry('DEVICE_METADATA', 'localhost', device_metadata)
return buffer_model_changed
@qos.command('reload')
@click.pass_context
@click.option('--no-dynamic-buffer', is_flag=True, help="Disable dynamic buffer calculation")
@click.option(
'--json-data', type=click.STRING,
help="json string with additional data, valid with --dry-run option"
)
@click.option(
'--dry_run', type=click.STRING,
help="Dry run, writes config to the given file"
)
def reload(ctx, no_dynamic_buffer, dry_run, json_data):
"""Reload QoS configuration"""
log.log_info("'qos reload' executing...")
_clear_qos()
_, hwsku_path = device_info.get_paths_to_platform_and_hwsku_dirs()
sonic_version_file = device_info.get_sonic_version_file()
from_db = "-d --write-to-db"
if dry_run:
from_db = "--additional-data \'{}\'".format(json_data) if json_data else ""
namespace_list = [DEFAULT_NAMESPACE]
if multi_asic.get_num_asics() > 1:
namespace_list = multi_asic.get_namespaces_from_linux()
buffer_model_updated = False
vendors_supporting_dynamic_buffer = ["mellanox"]
for ns in namespace_list:
if ns is DEFAULT_NAMESPACE:
asic_id_suffix = ""
config_db = ConfigDBConnector()
else:
asic_id = multi_asic.get_asic_id_from_name(ns)
if asic_id is None:
click.secho(
"Command 'qos reload' failed with invalid namespace '{}'".
format(ns),
fg="yellow"
)
raise click.Abort()
asic_id_suffix = str(asic_id)
config_db = ConfigDBConnector(
use_unix_socket_path=True, namespace=ns
)
config_db.connect()
if not no_dynamic_buffer and asic_type in vendors_supporting_dynamic_buffer:
buffer_template_file = os.path.join(hwsku_path, asic_id_suffix, "buffers_dynamic.json.j2")
buffer_model_updated |= _update_buffer_calculation_model(config_db, "dynamic")
else:
buffer_template_file = os.path.join(hwsku_path, asic_id_suffix, "buffers.json.j2")
if asic_type in vendors_supporting_dynamic_buffer:
buffer_model_updated |= _update_buffer_calculation_model(config_db, "traditional")
if os.path.isfile(buffer_template_file):
qos_template_file = os.path.join(
hwsku_path, asic_id_suffix, "qos.json.j2"
)
if os.path.isfile(qos_template_file):
cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
fname = "{}{}".format(dry_run, asic_id_suffix) if dry_run else "config-db"
command = "{} {} {} -t {},{} -t {},{} -y {}".format(
SONIC_CFGGEN_PATH, cmd_ns, from_db, buffer_template_file,
fname, qos_template_file, fname, sonic_version_file
)
# Apply the configurations only when both buffer and qos
# configuration files are present
clicommon.run_command(command, display_cmd=True)
else:
click.secho("QoS definition template not found at {}".format(
qos_template_file
), fg="yellow")
else:
click.secho("Buffer definition template not found at {}".format(
buffer_template_file
), fg="yellow")
if buffer_model_updated:
print("Buffer calculation model updated, restarting swss is required to take effect")
def is_dynamic_buffer_enabled(config_db):
"""Return whether the current system supports dynamic buffer calculation"""
device_metadata = config_db.get_entry('DEVICE_METADATA', 'localhost')
return 'dynamic' == device_metadata.get('buffer_model')
#
# 'warm_restart' group ('config warm_restart ...')
#
@config.group(cls=clicommon.AbbreviationGroup, name='warm_restart')
@click.pass_context
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
def warm_restart(ctx, redis_unix_socket_path):
"""warm_restart-related configuration tasks"""
# Note: redis_unix_socket_path is a path string, and the ground truth is now from database_config.json.
# We only use it as a bool indicator on either unix_socket_path or tcp port
use_unix_socket_path = bool(redis_unix_socket_path)
config_db = ConfigDBConnector(use_unix_socket_path=use_unix_socket_path)
config_db.connect(wait_for_init=False)
# warm restart enable/disable config is put in stateDB, not persistent across cold reboot, not saved to config_DB.json file
state_db = SonicV2Connector(use_unix_socket_path=use_unix_socket_path)
state_db.connect(state_db.STATE_DB, False)
TABLE_NAME_SEPARATOR = '|'
prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR
ctx.obj = {'db': config_db, 'state_db': state_db, 'prefix': prefix}
@warm_restart.command('enable')
@click.argument('module', metavar='<module>', default='system', required=False)
@click.pass_context
def warm_restart_enable(ctx, module):
state_db = ctx.obj['state_db']
config_db = ctx.obj['db']
feature_table = config_db.get_table('FEATURE')
if module != 'system' and module not in feature_table:
exit('Feature {} is unknown'.format(module))
prefix = ctx.obj['prefix']
_hash = '{}{}'.format(prefix, module)
state_db.set(state_db.STATE_DB, _hash, 'enable', 'true')
state_db.close(state_db.STATE_DB)
@warm_restart.command('disable')
@click.argument('module', metavar='<module>', default='system', required=False)
@click.pass_context
def warm_restart_enable(ctx, module):
state_db = ctx.obj['state_db']
config_db = ctx.obj['db']
feature_table = config_db.get_table('FEATURE')
if module != 'system' and module not in feature_table:
exit('Feature {} is unknown'.format(module))
prefix = ctx.obj['prefix']
_hash = '{}{}'.format(prefix, module)
state_db.set(state_db.STATE_DB, _hash, 'enable', 'false')
state_db.close(state_db.STATE_DB)
@warm_restart.command('neighsyncd_timer')
@click.argument('seconds', metavar='<seconds>', required=True, type=int)
@click.pass_context
def warm_restart_neighsyncd_timer(ctx, seconds):
db = ctx.obj['db']
if seconds not in range(1, 9999):
ctx.fail("neighsyncd warm restart timer must be in range 1-9999")
db.mod_entry('WARM_RESTART', 'swss', {'neighsyncd_timer': seconds})
@warm_restart.command('bgp_timer')
@click.argument('seconds', metavar='<seconds>', required=True, type=int)
@click.pass_context
def warm_restart_bgp_timer(ctx, seconds):
db = ctx.obj['db']
if seconds not in range(1, 3600):
ctx.fail("bgp warm restart timer must be in range 1-3600")
db.mod_entry('WARM_RESTART', 'bgp', {'bgp_timer': seconds})
@warm_restart.command('teamsyncd_timer')
@click.argument('seconds', metavar='<seconds>', required=True, type=int)
@click.pass_context
def warm_restart_teamsyncd_timer(ctx, seconds):
db = ctx.obj['db']
if seconds not in range(1, 3600):
ctx.fail("teamsyncd warm restart timer must be in range 1-3600")
db.mod_entry('WARM_RESTART', 'teamd', {'teamsyncd_timer': seconds})
@warm_restart.command('bgp_eoiu')
@click.argument('enable', metavar='<enable>', default='true', required=False, type=click.Choice(["true", "false"]))
@click.pass_context
def warm_restart_bgp_eoiu(ctx, enable):
db = ctx.obj['db']
db.mod_entry('WARM_RESTART', 'bgp', {'bgp_eoiu': enable})
def mvrf_restart_services():
"""Restart interfaces-config service and NTP service when mvrf is changed"""
"""
When mvrf is enabled, eth0 should be moved to mvrf; when it is disabled,
move it back to default vrf. Restarting the "interfaces-config" service
will recreate the /etc/network/interfaces file and restart the
"networking" service that takes care of the eth0 movement.
NTP service should also be restarted to rerun the NTP service with or
without "cgexec" accordingly.
"""
cmd="service ntp stop"
os.system (cmd)
cmd="systemctl restart interfaces-config"
os.system (cmd)
cmd="service ntp start"
os.system (cmd)
def vrf_add_management_vrf(config_db):
"""Enable management vrf in config DB"""
entry = config_db.get_entry('MGMT_VRF_CONFIG', "vrf_global")
if entry and entry['mgmtVrfEnabled'] == 'true' :
click.echo("ManagementVRF is already Enabled.")
return None
config_db.mod_entry('MGMT_VRF_CONFIG', "vrf_global", {"mgmtVrfEnabled": "true"})
mvrf_restart_services()
"""
The regular expression for grep in below cmd is to match eth0 line in /proc/net/route, sample file:
$ cat /proc/net/route
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
eth0 00000000 01803B0A 0003 0 0 202 00000000 0 0 0
"""
cmd = r"cat /proc/net/route | grep -E \"eth0\s+00000000\s+[0-9A-Z]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+202\" | wc -l"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
output = proc.communicate()
if int(output[0]) >= 1:
cmd="ip -4 route del default dev eth0 metric 202"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
proc.communicate()
if proc.returncode != 0:
click.echo("Could not delete eth0 route")
def vrf_delete_management_vrf(config_db):
"""Disable management vrf in config DB"""
entry = config_db.get_entry('MGMT_VRF_CONFIG', "vrf_global")
if not entry or entry['mgmtVrfEnabled'] == 'false' :
click.echo("ManagementVRF is already Disabled.")
return None
config_db.mod_entry('MGMT_VRF_CONFIG', "vrf_global", {"mgmtVrfEnabled": "false"})
mvrf_restart_services()
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def snmpagentaddress(ctx):
"""SNMP agent listening IP address, port, vrf configuration"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
ip_family = {4: AF_INET, 6: AF_INET6}
@snmpagentaddress.command('add')
@click.argument('agentip', metavar='<SNMP AGENT LISTENING IP Address>', required=True)
@click.option('-p', '--port', help="SNMP AGENT LISTENING PORT")
@click.option('-v', '--vrf', help="VRF Name mgmt/DataVrfName/None")
@click.pass_context
def add_snmp_agent_address(ctx, agentip, port, vrf):
"""Add the SNMP agent listening IP:Port%Vrf configuration"""
#Construct SNMP_AGENT_ADDRESS_CONFIG table key in the format ip|<port>|<vrf>
if not clicommon.is_ipaddress(agentip):
click.echo("Invalid IP address")
return False
config_db = ctx.obj['db']
if not vrf:
entry = config_db.get_entry('MGMT_VRF_CONFIG', "vrf_global")
if entry and entry['mgmtVrfEnabled'] == 'true' :
click.echo("ManagementVRF is Enabled. Provide vrf.")
return False
found = 0
ip = ipaddress.ip_address(agentip)
for intf in netifaces.interfaces():
ipaddresses = netifaces.ifaddresses(intf)
if ip_family[ip.version] in ipaddresses:
for ipaddr in ipaddresses[ip_family[ip.version]]:
if agentip.lower() == ipaddr['addr'].lower():
found = 1
break
if found == 1:
break
else:
click.echo("IP address is not available")
return
key = agentip+'|'
if port:
key = key+port
#snmpd does not start if we have two entries with same ip and port.
key1 = "SNMP_AGENT_ADDRESS_CONFIG|" + key + '*'
entry = config_db.get_keys(key1)
if entry:
ip_port = agentip + ":" + port
click.echo("entry with {} already exists ".format(ip_port))
return
key = key+'|'
if vrf:
key = key+vrf
config_db.set_entry('SNMP_AGENT_ADDRESS_CONFIG', key, {})
#Restarting the SNMP service will regenerate snmpd.conf and rerun snmpd
cmd="systemctl restart snmp"
os.system (cmd)
@snmpagentaddress.command('del')
@click.argument('agentip', metavar='<SNMP AGENT LISTENING IP Address>', required=True)
@click.option('-p', '--port', help="SNMP AGENT LISTENING PORT")
@click.option('-v', '--vrf', help="VRF Name mgmt/DataVrfName/None")
@click.pass_context
def del_snmp_agent_address(ctx, agentip, port, vrf):
"""Delete the SNMP agent listening IP:Port%Vrf configuration"""
key = agentip+'|'
if port:
key = key+port
key = key+'|'
if vrf:
key = key+vrf
config_db = ctx.obj['db']
config_db.set_entry('SNMP_AGENT_ADDRESS_CONFIG', key, None)
cmd="systemctl restart snmp"
os.system (cmd)
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def snmptrap(ctx):
"""SNMP Trap server configuration to send traps"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
@snmptrap.command('modify')
@click.argument('ver', metavar='<SNMP Version>', type=click.Choice(['1', '2', '3']), required=True)
@click.argument('serverip', metavar='<SNMP TRAP SERVER IP Address>', required=True)
@click.option('-p', '--port', help="SNMP Trap Server port, default 162", default="162")
@click.option('-v', '--vrf', help="VRF Name mgmt/DataVrfName/None", default="None")
@click.option('-c', '--comm', help="Community", default="public")
@click.pass_context
def modify_snmptrap_server(ctx, ver, serverip, port, vrf, comm):
"""Modify the SNMP Trap server configuration"""
#SNMP_TRAP_CONFIG for each SNMP version
config_db = ctx.obj['db']
if ver == "1":
#By default, v1TrapDest value in snmp.yml is "NotConfigured". Modify it.
config_db.mod_entry('SNMP_TRAP_CONFIG', "v1TrapDest", {"DestIp": serverip, "DestPort": port, "vrf": vrf, "Community": comm})
elif ver == "2":
config_db.mod_entry('SNMP_TRAP_CONFIG', "v2TrapDest", {"DestIp": serverip, "DestPort": port, "vrf": vrf, "Community": comm})
else:
config_db.mod_entry('SNMP_TRAP_CONFIG', "v3TrapDest", {"DestIp": serverip, "DestPort": port, "vrf": vrf, "Community": comm})
cmd="systemctl restart snmp"
os.system (cmd)
@snmptrap.command('del')
@click.argument('ver', metavar='<SNMP Version>', type=click.Choice(['1', '2', '3']), required=True)
@click.pass_context
def delete_snmptrap_server(ctx, ver):
"""Delete the SNMP Trap server configuration"""
config_db = ctx.obj['db']
if ver == "1":
config_db.mod_entry('SNMP_TRAP_CONFIG', "v1TrapDest", None)
elif ver == "2":
config_db.mod_entry('SNMP_TRAP_CONFIG', "v2TrapDest", None)
else:
config_db.mod_entry('SNMP_TRAP_CONFIG', "v3TrapDest", None)
cmd="systemctl restart snmp"
os.system (cmd)
#
# 'snmp' group ('config snmp ...')
#
@config.group(cls=clicommon.AbbreviationGroup, name='snmp')
@clicommon.pass_db
def snmp(db):
"""SNMP configuration tasks"""
@snmp.group(cls=clicommon.AbbreviationGroup)
@clicommon.pass_db
def community(db):
pass
def is_valid_community_type(commstr_type):
commstr_types = ['RO', 'RW']
if commstr_type not in commstr_types:
click.echo("Invalid community type. Must be either RO or RW")
return False
return True
def is_valid_user_type(user_type):
convert_user_type = {'noauthnopriv': 'noAuthNoPriv', 'authnopriv': 'AuthNoPriv', 'priv': 'Priv'}
if user_type not in convert_user_type:
message = ("Invalid user type. Must be one of these one of these three "
"'noauthnopriv' or 'authnopriv' or 'priv'")
click.echo(message)
return False, message
return True, convert_user_type[user_type]
def is_valid_auth_type(user_auth_type):
user_auth_types = ['MD5', 'SHA', 'HMAC-SHA-2']
if user_auth_type not in user_auth_types:
click.echo("Invalid user authentication type. Must be one of these 'MD5', 'SHA', or 'HMAC-SHA-2'")
return False
return True
def is_valid_encrypt_type(encrypt_type):
encrypt_types = ['DES', 'AES']
if encrypt_type not in encrypt_types:
click.echo("Invalid user encryption type. Must be one of these two 'DES' or 'AES'")
return False
return True
def snmp_community_secret_check(snmp_secret):
excluded_special_symbols = ['@', ":"]
if len(snmp_secret) > 32:
click.echo("SNMP community string length should be not be greater than 32")
click.echo("SNMP community string should not have any of these special "
"symbols {}".format(excluded_special_symbols))
click.echo("FAILED: SNMP community string length should be not be greater than 32")
return False
if any(char in excluded_special_symbols for char in snmp_secret):
click.echo("SNMP community string length should be not be greater than 32")
click.echo("SNMP community string should not have any of these special "
"symbols {}".format(excluded_special_symbols))
click.echo("FAILED: SNMP community string should not have any of these "
"special symbols {}".format(excluded_special_symbols))
return False
return True
def snmp_username_check(snmp_username):
excluded_special_symbols = ['@', ":"]
if len(snmp_username) > 32:
click.echo("SNMP user {} length should be not be greater than 32 characters".format(snmp_username))
click.echo("SNMP community string should not have any of these special "
"symbols {}".format(excluded_special_symbols))
click.echo("FAILED: SNMP user {} length should not be greater than 32 characters".format(snmp_username))
return False
if any(char in excluded_special_symbols for char in snmp_username):
click.echo("SNMP user {} length should be not be greater than 32 characters".format(snmp_username))
click.echo("SNMP community string should not have any of these special "
"symbols {}".format(excluded_special_symbols))
click.echo("FAILED: SNMP user {} should not have any of these special "
"symbols {}".format(snmp_username, excluded_special_symbols))
return False
return True
def snmp_user_secret_check(snmp_secret):
excluded_special_symbols = ['@', ":"]
if len(snmp_secret) < 8:
click.echo("SNMP user password length should be at least 8 characters")
click.echo("SNMP user password length should be not be greater than 64")
click.echo("SNMP user password should not have any of these special "
"symbols {}".format(excluded_special_symbols))
click.echo("FAILED: SNMP user password length should be at least 8 characters")
return False
if len(snmp_secret) > 64:
click.echo("SNMP user password length should be at least 8 characters")
click.echo("SNMP user password length should be not be greater than 64")
click.echo("SNMP user password should not have any of these special "
"symbols {}".format(excluded_special_symbols))
click.echo("FAILED: SNMP user password length should be not be greater than 64")
return False
if any(char in excluded_special_symbols for char in snmp_secret):
click.echo("SNMP user password length should be at least 8 characters")
click.echo("SNMP user password length should be not be greater than 64")
click.echo("SNMP user password should not have any of these special "
"symbols {}".format(excluded_special_symbols))
click.echo("FAILED: SNMP user password should not have any of these special "
"symbols {}".format(excluded_special_symbols))
return False
return True
@community.command('add')
@click.argument('community', metavar='<snmp_community>', required=True)
@click.argument('string_type', metavar='<RO|RW>', required=True)
@clicommon.pass_db
def add_community(db, community, string_type):
""" Add snmp community string"""
string_type = string_type.upper()
if not is_valid_community_type(string_type):
sys.exit(1)
if not snmp_community_secret_check(community):
sys.exit(2)
snmp_communities = db.cfgdb.get_table("SNMP_COMMUNITY")
if community in snmp_communities:
click.echo("SNMP community {} is already configured".format(community))
sys.exit(3)
db.cfgdb.set_entry('SNMP_COMMUNITY', community, {'TYPE': string_type})
click.echo("SNMP community {} added to configuration".format(community))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
@community.command('del')
@click.argument('community', metavar='<snmp_community>', required=True)
@clicommon.pass_db
def del_community(db, community):
""" Delete snmp community string"""
snmp_communities = db.cfgdb.get_table("SNMP_COMMUNITY")
if community not in snmp_communities:
click.echo("SNMP community {} is not configured".format(community))
sys.exit(1)
else:
db.cfgdb.set_entry('SNMP_COMMUNITY', community, None)
click.echo("SNMP community {} removed from configuration".format(community))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
@community.command('replace')
@click.argument('current_community', metavar='<current_community_string>', required=True)
@click.argument('new_community', metavar='<new_community_string>', required=True)
@clicommon.pass_db
def replace_community(db, current_community, new_community):
""" Replace snmp community string"""
snmp_communities = db.cfgdb.get_table("SNMP_COMMUNITY")
if not current_community in snmp_communities:
click.echo("Current SNMP community {} is not configured".format(current_community))
sys.exit(1)
if not snmp_community_secret_check(new_community):
sys.exit(2)
elif new_community in snmp_communities:
click.echo("New SNMP community {} to replace current SNMP community {} already "
"configured".format(new_community, current_community))
sys.exit(3)
else:
string_type = snmp_communities[current_community]['TYPE']
db.cfgdb.set_entry('SNMP_COMMUNITY', new_community, {'TYPE': string_type})
click.echo("SNMP community {} added to configuration".format(new_community))
db.cfgdb.set_entry('SNMP_COMMUNITY', current_community, None)
click.echo('SNMP community {} replace community {}'.format(new_community, current_community))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
@snmp.group(cls=clicommon.AbbreviationGroup)
@clicommon.pass_db
def contact(db):
pass
def is_valid_email(email):
return bool(re.search(r"^[\w\.\+\-]+\@[\w]+\.[a-z]{2,3}$", email))
@contact.command('add')
@click.argument('contact', metavar='<contact_name>', required=True)
@click.argument('contact_email', metavar='<contact_email>', required=True)
@clicommon.pass_db
def add_contact(db, contact, contact_email):
""" Add snmp contact name and email """
snmp = db.cfgdb.get_table("SNMP")
try:
if snmp['CONTACT']:
click.echo("Contact already exists. Use sudo config snmp contact modify instead")
sys.exit(1)
else:
db.cfgdb.set_entry('SNMP', 'CONTACT', {contact: contact_email})
click.echo("Contact name {} and contact email {} have been added to "
"configuration".format(contact, contact_email))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
except KeyError:
if "CONTACT" not in snmp.keys():
if not is_valid_email(contact_email):
click.echo("Contact email {} is not valid".format(contact_email))
sys.exit(2)
db.cfgdb.set_entry('SNMP', 'CONTACT', {contact: contact_email})
click.echo("Contact name {} and contact email {} have been added to "
"configuration".format(contact, contact_email))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
@contact.command('del')
@click.argument('contact', metavar='<contact_name>', required=True)
@clicommon.pass_db
def del_contact(db, contact):
""" Delete snmp contact name and email """
snmp = db.cfgdb.get_table("SNMP")
try:
if not contact in (list(snmp['CONTACT'].keys()))[0]:
click.echo("SNMP contact {} is not configured".format(contact))
sys.exit(1)
else:
db.cfgdb.set_entry('SNMP', 'CONTACT', None)
click.echo("SNMP contact {} removed from configuration".format(contact))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
except KeyError:
if "CONTACT" not in snmp.keys():
click.echo("Contact name {} is not configured".format(contact))
sys.exit(2)
@contact.command('modify')
@click.argument('contact', metavar='<contact>', required=True)
@click.argument('contact_email', metavar='<contact email>', required=True)
@clicommon.pass_db
def modify_contact(db, contact, contact_email):
""" Modify snmp contact"""
snmp = db.cfgdb.get_table("SNMP")
try:
current_snmp_contact_name = (list(snmp['CONTACT'].keys()))[0]
if current_snmp_contact_name == contact:
current_snmp_contact_email = snmp['CONTACT'][contact]
else:
current_snmp_contact_email = ''
if contact == current_snmp_contact_name and contact_email == current_snmp_contact_email:
click.echo("SNMP contact {} {} already exists".format(contact, contact_email))
sys.exit(1)
elif contact == current_snmp_contact_name and contact_email != current_snmp_contact_email:
if not is_valid_email(contact_email):
click.echo("Contact email {} is not valid".format(contact_email))
sys.exit(2)
db.cfgdb.mod_entry('SNMP', 'CONTACT', {contact: contact_email})
click.echo("SNMP contact {} email updated to {}".format(contact, contact_email))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
else:
if not is_valid_email(contact_email):
click.echo("Contact email {} is not valid".format(contact_email))
sys.exit(2)
db.cfgdb.set_entry('SNMP', 'CONTACT', None)
db.cfgdb.set_entry('SNMP', 'CONTACT', {contact: contact_email})
click.echo("SNMP contact {} and contact email {} updated".format(contact, contact_email))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
except KeyError:
if "CONTACT" not in snmp.keys():
click.echo("Contact name {} is not configured".format(contact))
sys.exit(3)
@snmp.group(cls=clicommon.AbbreviationGroup)
@clicommon.pass_db
def location(db):
pass
@location.command('add')
@click.argument('location', metavar='<location>', required=True, nargs=-1)
@clicommon.pass_db
def add_location(db, location):
""" Add snmp location"""
if isinstance(location, tuple):
location = " ".join(location)
elif isinstance(location, list):
location = " ".join(location)
snmp = db.cfgdb.get_table("SNMP")
try:
if snmp['LOCATION']:
click.echo("Location already exists")
sys.exit(1)
except KeyError:
if "LOCATION" not in snmp.keys():
db.cfgdb.set_entry('SNMP', 'LOCATION', {'Location': location})
click.echo("SNMP Location {} has been added to configuration".format(location))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
@location.command('del')
@click.argument('location', metavar='<location>', required=True, nargs=-1)
@clicommon.pass_db
def delete_location(db, location):
""" Delete snmp location"""
if isinstance(location, tuple):
location = " ".join(location)
elif isinstance(location, list):
location = " ".join(location)
snmp = db.cfgdb.get_table("SNMP")
try:
if location == snmp['LOCATION']['Location']:
db.cfgdb.set_entry('SNMP', 'LOCATION', None)
click.echo("SNMP Location {} removed from configuration".format(location))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
else:
click.echo("SNMP Location {} does not exist. The location is {}".format(location, snmp['LOCATION']['Location']))
sys.exit(1)
except KeyError:
if "LOCATION" not in snmp.keys():
click.echo("SNMP Location {} is not configured".format(location))
sys.exit(2)
@location.command('modify')
@click.argument('location', metavar='<location>', required=True, nargs=-1)
@clicommon.pass_db
def modify_location(db, location):
""" Modify snmp location"""
if isinstance(location, tuple):
location = " ".join(location)
elif isinstance(location, list):
location = " ".join(location)
snmp = db.cfgdb.get_table("SNMP")
try:
snmp_location = snmp['LOCATION']['Location']
if location in snmp_location:
click.echo("SNMP location {} already exists".format(location))
sys.exit(1)
else:
db.cfgdb.mod_entry('SNMP', 'LOCATION', {'Location': location})
click.echo("SNMP location {} modified in configuration".format(location))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
except KeyError:
click.echo("Cannot modify SNMP Location. You must use 'config snmp location add command <snmp_location>'")
sys.exit(2)
from enum import IntEnum
class SnmpUserError(IntEnum):
NameCheckFailure = 1
TypeNoAuthNoPrivOrAuthNoPrivOrPrivCheckFailure = 2
RoRwCheckFailure = 3
NoAuthNoPrivHasAuthType = 4
AuthTypeMd5OrShaOrHmacsha2IsMissing = 5
AuthTypeMd5OrShaOrHmacsha2Failure = 6
AuthPasswordMissing = 7
AuthPasswordFailsComplexityRequirements = 8
EncryptPasswordNotAllowedWithAuthNoPriv = 9
EncryptTypeDesOrAesIsMissing = 10
EncryptTypeFailsComplexityRequirements = 11
EncryptPasswordMissingFailure = 12
EncryptPasswordFailsComplexityRequirements = 13
UserAlreadyConfigured = 14
@snmp.group(cls=clicommon.AbbreviationGroup)
@clicommon.pass_db
def user(db):
pass
@user.command('add')
@click.argument('user', metavar='<snmp_user>', required=True)
@click.argument('user_type', metavar='<noAuthNoPriv|AuthNoPriv|Priv>', required=True)
@click.argument('user_permission_type', metavar='<RO|RW>', required=True)
@click.argument('user_auth_type', metavar='<MD5|SHA|HMAC-SHA-2>', required=False)
@click.argument('user_auth_password', metavar='<auth_password>', required=False)
@click.argument('user_encrypt_type', metavar='<DES|AES>', required=False)
@click.argument('user_encrypt_password', metavar='<encrypt_password>', required=False)
@clicommon.pass_db
def add_user(db, user, user_type, user_permission_type, user_auth_type, user_auth_password, user_encrypt_type,
user_encrypt_password):
""" Add snmp user"""
if not snmp_username_check(user):
sys.exit(SnmpUserError.NameCheckFailure)
user_type = user_type.lower()
user_type_info = is_valid_user_type(user_type)
if not user_type_info[0]:
sys.exit(SnmpUserError.TypeNoAuthNoPrivOrAuthNoPrivOrPrivCheckFailure)
user_type = user_type_info[1]
user_permission_type = user_permission_type.upper()
if not is_valid_community_type(user_permission_type):
sys.exit(SnmpUserError.RoRwCheckFailure)
if user_type == "noAuthNoPriv":
if user_auth_type:
click.echo("User auth type not used with 'noAuthNoPriv'. Please use 'AuthNoPriv' or 'Priv' instead")
sys.exit(SnmpUserError.NoAuthNoPrivHasAuthType)
else:
if not user_auth_type:
click.echo("User auth type is missing. Must be MD5, SHA, or HMAC-SHA-2")
sys.exit(SnmpUserError.AuthTypeMd5OrShaOrHmacsha2IsMissing)
if user_auth_type:
user_auth_type = user_auth_type.upper()
if not is_valid_auth_type(user_auth_type):
sys.exit(SnmpUserError.AuthTypeMd5OrShaOrHmacsha2Failure)
elif not user_auth_password:
click.echo("User auth password is missing")
sys.exit(SnmpUserError.AuthPasswordMissing)
elif user_auth_password:
if not snmp_user_secret_check(user_auth_password):
sys.exit(SnmpUserError.AuthPasswordFailsComplexityRequirements)
if user_type == "AuthNoPriv":
if user_encrypt_type:
click.echo("User encrypt type not used with 'AuthNoPriv'. Please use 'Priv' instead")
sys.exit(SnmpUserError.EncryptPasswordNotAllowedWithAuthNoPriv)
elif user_type == "Priv":
if not user_encrypt_type:
click.echo("User encrypt type is missing. Must be DES or AES")
sys.exit(SnmpUserError.EncryptTypeDesOrAesIsMissing)
if user_encrypt_type:
user_encrypt_type = user_encrypt_type.upper()
if not is_valid_encrypt_type(user_encrypt_type):
sys.exit(SnmpUserError.EncryptTypeFailsComplexityRequirements)
elif not user_encrypt_password:
click.echo("User encrypt password is missing")
sys.exit(SnmpUserError.EncryptPasswordMissingFailure)
elif user_encrypt_password:
if not snmp_user_secret_check(user_encrypt_password):
sys.exit(SnmpUserError.EncryptPasswordFailsComplexityRequirements)
snmp_users = db.cfgdb.get_table("SNMP_USER")
if user in snmp_users.keys():
click.echo("SNMP user {} is already configured".format(user))
sys.exit(SnmpUserError.UserAlreadyConfigured)
else:
if not user_auth_type:
user_auth_type = ''
if not user_auth_password:
user_auth_password = ''
if not user_encrypt_type:
user_encrypt_type = ''
if not user_encrypt_password:
user_encrypt_password = ''
db.cfgdb.set_entry('SNMP_USER', user, {'SNMP_USER_TYPE': user_type,
'SNMP_USER_PERMISSION': user_permission_type,
'SNMP_USER_AUTH_TYPE': user_auth_type,
'SNMP_USER_AUTH_PASSWORD': <PASSWORD>,
'SNMP_USER_ENCRYPTION_TYPE': user_encrypt_type,
'SNMP_USER_ENCRYPTION_PASSWORD': <PASSWORD>})
click.echo("SNMP user {} added to configuration".format(user))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
@user.command('del')
@click.argument('user', metavar='<snmp_user>', required=True)
@clicommon.pass_db
def del_user(db, user):
""" Del snmp user"""
snmp_users = db.cfgdb.get_table("SNMP_USER")
if user not in snmp_users:
click.echo("SNMP user {} is not configured".format(user))
sys.exit(1)
else:
db.cfgdb.set_entry('SNMP_USER', user, None)
click.echo("SNMP user {} removed from configuration".format(user))
try:
click.echo("Restarting SNMP service...")
clicommon.run_command("systemctl reset-failed snmp.service", display_cmd=False)
clicommon.run_command("systemctl restart snmp.service", display_cmd=False)
except SystemExit as e:
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()
#
# 'bgp' group ('config bgp ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
def bgp():
"""BGP-related configuration tasks"""
pass
#
# 'shutdown' subgroup ('config bgp shutdown ...')
#
@bgp.group(cls=clicommon.AbbreviationGroup)
def shutdown():
"""Shut down BGP session(s)"""
pass
# 'all' subcommand
@shutdown.command()
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def all(verbose):
"""Shut down all BGP sessions
In the case of Multi-Asic platform, we shut only the EBGP sessions with external neighbors.
"""
log.log_info("'bgp shutdown all' executing...")
namespaces = [DEFAULT_NAMESPACE]
if multi_asic.is_multi_asic():
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns']
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
for ipaddress in bgp_neighbor_ip_list:
_change_bgp_session_status_by_addr(config_db, ipaddress, 'down', verbose)
# 'neighbor' subcommand
@shutdown.command()
@click.argument('ipaddr_or_hostname', metavar='<ipaddr_or_hostname>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def neighbor(ipaddr_or_hostname, verbose):
"""Shut down BGP session by neighbor IP address or hostname.
User can specify either internal or external BGP neighbor to shutdown
"""
log.log_info("'bgp shutdown neighbor {}' executing...".format(ipaddr_or_hostname))
namespaces = [DEFAULT_NAMESPACE]
found_neighbor = False
if multi_asic.is_multi_asic():
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns'] + ns_list['back_ns']
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
if _change_bgp_session_status(config_db, ipaddr_or_hostname, 'down', verbose):
found_neighbor = True
if not found_neighbor:
click.get_current_context().fail("Could not locate neighbor '{}'".format(ipaddr_or_hostname))
@bgp.group(cls=clicommon.AbbreviationGroup)
def startup():
"""Start up BGP session(s)"""
pass
# 'all' subcommand
@startup.command()
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def all(verbose):
"""Start up all BGP sessions
In the case of Multi-Asic platform, we startup only the EBGP sessions with external neighbors.
"""
log.log_info("'bgp startup all' executing...")
namespaces = [DEFAULT_NAMESPACE]
if multi_asic.is_multi_asic():
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns']
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
bgp_neighbor_ip_list = _get_all_neighbor_ipaddresses(config_db)
for ipaddress in bgp_neighbor_ip_list:
_change_bgp_session_status_by_addr(config_db, ipaddress, 'up', verbose)
# 'neighbor' subcommand
@startup.command()
@click.argument('ipaddr_or_hostname', metavar='<ipaddr_or_hostname>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def neighbor(ipaddr_or_hostname, verbose):
log.log_info("'bgp startup neighbor {}' executing...".format(ipaddr_or_hostname))
"""Start up BGP session by neighbor IP address or hostname.
User can specify either internal or external BGP neighbor to startup
"""
namespaces = [DEFAULT_NAMESPACE]
found_neighbor = False
if multi_asic.is_multi_asic():
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns'] + ns_list['back_ns']
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
if _change_bgp_session_status(config_db, ipaddr_or_hostname, 'up', verbose):
found_neighbor = True
if not found_neighbor:
click.get_current_context().fail("Could not locate neighbor '{}'".format(ipaddr_or_hostname))
#
# 'remove' subgroup ('config bgp remove ...')
#
@bgp.group(cls=clicommon.AbbreviationGroup)
def remove():
"Remove BGP neighbor configuration from the device"
pass
@remove.command('neighbor')
@click.argument('neighbor_ip_or_hostname', metavar='<neighbor_ip_or_hostname>', required=True)
def remove_neighbor(neighbor_ip_or_hostname):
"""Deletes BGP neighbor configuration of given hostname or ip from devices
User can specify either internal or external BGP neighbor to remove
"""
namespaces = [DEFAULT_NAMESPACE]
removed_neighbor = False
if multi_asic.is_multi_asic():
ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns'] + ns_list['back_ns']
# Connect to CONFIG_DB in linux host (in case of single ASIC) or CONFIG_DB in all the
# namespaces (in case of multi ASIC) and do the sepcified "action" on the BGP neighbor(s)
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()
if _remove_bgp_neighbor_config(config_db, neighbor_ip_or_hostname):
removed_neighbor = True
if not removed_neighbor:
click.get_current_context().fail("Could not locate neighbor '{}'".format(neighbor_ip_or_hostname))
#
# 'interface' group ('config interface ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
# TODO add "hidden=True if this is a single ASIC platform, once we have click 7.0 in all branches.
@click.option('-n', '--namespace', help='Namespace name',
required=True if multi_asic.is_multi_asic() else False, type=click.Choice(multi_asic.get_namespace_list()))
@click.pass_context
def interface(ctx, namespace):
"""Interface-related configuration tasks"""
# Set namespace to default_namespace if it is None.
if namespace is None:
namespace = DEFAULT_NAMESPACE
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=str(namespace))
config_db.connect()
ctx.obj = {'config_db': config_db, 'namespace': str(namespace)}
#
# 'startup' subcommand
#
@interface.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.pass_context
def startup(ctx, interface_name):
"""Start up interface"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
intf_fs = parse_interface_in_filter(interface_name)
if len(intf_fs) > 1 and multi_asic.is_multi_asic():
ctx.fail("Interface range not supported in multi-asic platforms !!")
if len(intf_fs) == 1 and interface_name_is_valid(config_db, interface_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
log.log_info("'interface startup {}' executing...".format(interface_name))
port_dict = config_db.get_table('PORT')
for port_name in port_dict:
if port_name in intf_fs:
config_db.mod_entry("PORT", port_name, {"admin_status": "up"})
portchannel_list = config_db.get_table("PORTCHANNEL")
for po_name in portchannel_list:
if po_name in intf_fs:
config_db.mod_entry("PORTCHANNEL", po_name, {"admin_status": "up"})
subport_list = config_db.get_table("VLAN_SUB_INTERFACE")
for sp_name in subport_list:
if sp_name in intf_fs:
config_db.mod_entry("VLAN_SUB_INTERFACE", sp_name, {"admin_status": "up"})
#
# 'shutdown' subcommand
#
@interface.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.pass_context
def shutdown(ctx, interface_name):
"""Shut down interface"""
log.log_info("'interface shutdown {}' executing...".format(interface_name))
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
intf_fs = parse_interface_in_filter(interface_name)
if len(intf_fs) > 1 and multi_asic.is_multi_asic():
ctx.fail("Interface range not supported in multi-asic platforms !!")
if len(intf_fs) == 1 and interface_name_is_valid(config_db, interface_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
port_dict = config_db.get_table('PORT')
for port_name in port_dict:
if port_name in intf_fs:
config_db.mod_entry("PORT", port_name, {"admin_status": "down"})
portchannel_list = config_db.get_table("PORTCHANNEL")
for po_name in portchannel_list:
if po_name in intf_fs:
config_db.mod_entry("PORTCHANNEL", po_name, {"admin_status": "down"})
subport_list = config_db.get_table("VLAN_SUB_INTERFACE")
for sp_name in subport_list:
if sp_name in intf_fs:
config_db.mod_entry("VLAN_SUB_INTERFACE", sp_name, {"admin_status": "down"})
#
# 'speed' subcommand
#
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_speed', metavar='<interface_speed>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def speed(ctx, interface_name, interface_speed, verbose):
"""Set interface speed"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
log.log_info("'interface speed {} {}' executing...".format(interface_name, interface_speed))
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -s {}".format(interface_name, interface_speed)
else:
command = "portconfig -p {} -s {} -n {}".format(interface_name, interface_speed, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'autoneg' subcommand
#
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('mode', metavar='<mode>', required=True, type=click.Choice(["enabled", "disabled"]))
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def autoneg(ctx, interface_name, mode, verbose):
"""Set interface auto negotiation mode"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
log.log_info("'interface autoneg {} {}' executing...".format(interface_name, mode))
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -an {}".format(interface_name, mode)
else:
command = "portconfig -p {} -an {} -n {}".format(interface_name, mode, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'adv-speeds' subcommand
#
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('speed_list', metavar='<speed_list>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def advertised_speeds(ctx, interface_name, speed_list, verbose):
"""Set interface advertised speeds"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
log.log_info("'interface advertised_speeds {} {}' executing...".format(interface_name, speed_list))
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -S {}".format(interface_name, speed_list)
else:
command = "portconfig -p {} -S {} -n {}".format(interface_name, speed_list, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'interface-type' subcommand
#
@interface.command(name='type')
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_type_value', metavar='<interface_type_value>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def interface_type(ctx, interface_name, interface_type_value, verbose):
"""Set interface type"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
log.log_info("'interface interface_type {} {}' executing...".format(interface_name, interface_type_value))
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -t {}".format(interface_name, interface_type_value)
else:
command = "portconfig -p {} -t {} -n {}".format(interface_name, interface_type_value, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'advertised-interface-types' subcommand
#
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_type_list', metavar='<interface_type_list>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def advertised_types(ctx, interface_name, interface_type_list, verbose):
"""Set interface advertised types"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
log.log_info("'interface advertised_interface_types {} {}' executing...".format(interface_name, interface_type_list))
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -T {}".format(interface_name, interface_type_list)
else:
command = "portconfig -p {} -T {} -n {}".format(interface_name, interface_type_list, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'breakout' subcommand
#
@interface.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('mode', required=True, type=click.STRING, autocompletion=_get_breakout_options)
@click.option('-f', '--force-remove-dependencies', is_flag=True, help='Clear all dependencies internally first.')
@click.option('-l', '--load-predefined-config', is_flag=True, help='load predefied user configuration (alias, lanes, speed etc) first.')
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false, expose_value=False, prompt='Do you want to Breakout the port, continue?')
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
@click.pass_context
def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load_predefined_config):
""" Set interface breakout mode """
breakout_cfg_file = device_info.get_path_to_port_config_file()
if not os.path.isfile(breakout_cfg_file) or not breakout_cfg_file.endswith('.json'):
click.secho("[ERROR] Breakout feature is not available without platform.json file", fg='red')
raise click.Abort()
# Get the config_db connector
config_db = ctx.obj['config_db']
target_brkout_mode = mode
# Get current breakout mode
cur_brkout_dict = config_db.get_table('BREAKOUT_CFG')
if len(cur_brkout_dict) == 0:
click.secho("[ERROR] BREAKOUT_CFG table is NOT present in CONFIG DB", fg='red')
raise click.Abort()
if interface_name not in cur_brkout_dict.keys():
click.secho("[ERROR] {} interface is NOT present in BREAKOUT_CFG table of CONFIG DB".format(interface_name), fg='red')
raise click.Abort()
cur_brkout_mode = cur_brkout_dict[interface_name]["brkout_mode"]
# Validate Interface and Breakout mode
if not _validate_interface_mode(ctx, breakout_cfg_file, interface_name, mode, cur_brkout_mode):
raise click.Abort()
""" Interface Deletion Logic """
# Get list of interfaces to be deleted
del_ports = get_child_ports(interface_name, cur_brkout_mode, breakout_cfg_file)
del_intf_dict = {intf: del_ports[intf]["speed"] for intf in del_ports}
if del_intf_dict:
click.echo("\nPorts to be deleted : \n {}".format(json.dumps(del_intf_dict, indent=4)))
else:
click.secho("[ERROR] del_intf_dict is None! No interfaces are there to be deleted", fg='red')
raise click.Abort()
""" Interface Addition Logic """
# Get list of interfaces to be added
add_ports = get_child_ports(interface_name, target_brkout_mode, breakout_cfg_file)
add_intf_dict = {intf: add_ports[intf]["speed"] for intf in add_ports}
if add_intf_dict:
click.echo("Ports to be added : \n {}".format(json.dumps(add_intf_dict, indent=4)))
else:
click.secho("[ERROR] port_dict is None!", fg='red')
raise click.Abort()
""" Special Case: Dont delete those ports where the current mode and speed of the parent port
remains unchanged to limit the traffic impact """
click.secho("\nAfter running Logic to limit the impact", fg="cyan", underline=True)
matched_items = [intf for intf in del_intf_dict if intf in add_intf_dict and del_intf_dict[intf] == add_intf_dict[intf]]
# Remove the interface which remains unchanged from both del_intf_dict and add_intf_dict
for item in matched_items:
del_intf_dict.pop(item)
add_intf_dict.pop(item)
# validate all del_ports before calling breakOutPort
for intf in del_intf_dict.keys():
if not interface_name_is_valid(config_db, intf):
click.secho("[ERROR] Interface name {} is invalid".format(intf))
raise click.Abort()
click.secho("\nFinal list of ports to be deleted : \n {} \nFinal list of ports to be added : \n {}".format(json.dumps(del_intf_dict, indent=4), json.dumps(add_intf_dict, indent=4), fg='green', blink=True))
if not add_intf_dict:
click.secho("[ERROR] add_intf_dict is None or empty! No interfaces are there to be added", fg='red')
raise click.Abort()
port_dict = {}
for intf in add_intf_dict:
if intf in add_ports:
port_dict[intf] = add_ports[intf]
# writing JSON object
with open('new_port_config.json', 'w') as f:
json.dump(port_dict, f, indent=4)
# Start Interation with Dy Port BreakOut Config Mgmt
try:
""" Load config for the commands which are capable of change in config DB """
cm = load_ConfigMgmt(verbose)
""" Delete all ports if forced else print dependencies using ConfigMgmt API """
final_delPorts = [intf for intf in del_intf_dict]
""" Warn user if tables without yang models exist and have final_delPorts """
breakout_warnUser_extraTables(cm, final_delPorts, confirm=True)
# Create a dictionary containing all the added ports with its capabilities like alias, lanes, speed etc.
portJson = dict(); portJson['PORT'] = port_dict
# breakout_Ports will abort operation on failure, So no need to check return
breakout_Ports(cm, delPorts=final_delPorts, portJson=portJson, force=force_remove_dependencies,
loadDefConfig=load_predefined_config, verbose=verbose)
# Set Current Breakout mode in config DB
brkout_cfg_keys = config_db.get_keys('BREAKOUT_CFG')
if interface_name not in brkout_cfg_keys:
click.secho("[ERROR] {} is not present in 'BREAKOUT_CFG' Table!".format(interface_name), fg='red')
raise click.Abort()
config_db.set_entry("BREAKOUT_CFG", interface_name, {'brkout_mode': target_brkout_mode})
click.secho("Breakout process got successfully completed."
.format(interface_name), fg="cyan", underline=True)
click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")
except Exception as e:
click.secho("Failed to break out Port. Error: {}".format(str(e)), fg='magenta')
sys.exit(0)
def _get_all_mgmtinterface_keys():
"""Returns list of strings containing mgmt interface keys
"""
config_db = ConfigDBConnector()
config_db.connect()
return list(config_db.get_table('MGMT_INTERFACE').keys())
def mgmt_ip_restart_services():
"""Restart the required services when mgmt inteface IP address is changed"""
"""
Whenever the eth0 IP address is changed, restart the "interfaces-config"
service which regenerates the /etc/network/interfaces file and restarts
the networking service to make the new/null IP address effective for eth0.
"ntp-config" service should also be restarted based on the new
eth0 IP address since the ntp.conf (generated from ntp.conf.j2) is
made to listen on that particular eth0 IP address or reset it back.
"""
cmd="systemctl restart interfaces-config"
os.system (cmd)
cmd="systemctl restart ntp-config"
os.system (cmd)
#
# 'mtu' subcommand
#
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_mtu', metavar='<interface_mtu>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def mtu(ctx, interface_name, interface_mtu, verbose):
"""Set interface mtu"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')
if interface_is_in_portchannel(portchannel_member_table, interface_name):
ctx.fail("'interface_name' is in portchannel!")
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -m {}".format(interface_name, interface_mtu)
else:
command = "portconfig -p {} -m {} -n {}".format(interface_name, interface_mtu, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'tpid' subcommand
#
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_tpid', metavar='<interface_tpid>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def tpid(ctx, interface_name, interface_tpid, verbose):
"""Set interface tpid"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -tp {}".format(interface_name, interface_tpid)
else:
command = "portconfig -p {} -tp {} -n {}".format(interface_name, interface_tpid, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_fec', metavar='<interface_fec>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def fec(ctx, interface_name, interface_fec, verbose):
"""Set interface fec"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if interface_fec not in ["rs", "fc", "none"]:
ctx.fail("'fec not in ['rs', 'fc', 'none']!")
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -f {}".format(interface_name, interface_fec)
else:
command = "portconfig -p {} -f {} -n {}".format(interface_name, interface_fec, ctx.obj['namespace'])
if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'ip' subgroup ('config interface ip ...')
#
@interface.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def ip(ctx):
"""Add or remove IP address"""
pass
#
# 'add' subcommand
#
@ip.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument("ip_addr", metavar="<ip_addr>", required=True)
@click.argument('gw', metavar='<default gateway IP address>', required=False)
@click.pass_context
def add(ctx, interface_name, ip_addr, gw):
"""Add an IP address towards the interface"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
# Add a validation to check this interface is not a member in vlan before
# changing it to a router port
vlan_member_table = config_db.get_table('VLAN_MEMBER')
if (interface_is_in_vlan(vlan_member_table, interface_name)):
click.echo("Interface {} is a member of vlan\nAborting!".format(interface_name))
return
try:
ip_address = ipaddress.ip_interface(ip_addr)
except ValueError as err:
ctx.fail("IP address is not valid: {}".format(err))
if interface_name == 'eth0':
# Configuring more than 1 IPv4 or more than 1 IPv6 address fails.
# Allow only one IPv4 and only one IPv6 address to be configured for IPv6.
# If a row already exist, overwrite it (by doing delete and add).
mgmtintf_key_list = _get_all_mgmtinterface_keys()
for key in mgmtintf_key_list:
# For loop runs for max 2 rows, once for IPv4 and once for IPv6.
# No need to capture the exception since the ip_addr is already validated earlier
current_ip = ipaddress.ip_interface(key[1])
if (ip_address.version == current_ip.version):
# If user has configured IPv4/v6 address and the already available row is also IPv4/v6, delete it here.
config_db.set_entry("MGMT_INTERFACE", ("eth0", key[1]), None)
# Set the new row with new value
if not gw:
config_db.set_entry("MGMT_INTERFACE", (interface_name, str(ip_address)), {"NULL": "NULL"})
else:
config_db.set_entry("MGMT_INTERFACE", (interface_name, str(ip_address)), {"gwaddr": gw})
mgmt_ip_restart_services()
return
table_name = get_interface_table_name(interface_name)
if table_name == "":
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan/Loopback]")
interface_entry = config_db.get_entry(table_name, interface_name)
if len(interface_entry) == 0:
if table_name == "VLAN_SUB_INTERFACE":
config_db.set_entry(table_name, interface_name, {"admin_status": "up"})
else:
config_db.set_entry(table_name, interface_name, {"NULL": "NULL"})
config_db.set_entry(table_name, (interface_name, str(ip_address)), {"NULL": "NULL"})
#
# 'del' subcommand
#
@ip.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument("ip_addr", metavar="<ip_addr>", required=True)
@click.pass_context
def remove(ctx, interface_name, ip_addr):
"""Remove an IP address from the interface"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
try:
ip_address = ipaddress.ip_interface(ip_addr)
except ValueError as err:
ctx.fail("IP address is not valid: {}".format(err))
if interface_name == 'eth0':
config_db.set_entry("MGMT_INTERFACE", (interface_name, str(ip_address)), None)
mgmt_ip_restart_services()
return
table_name = get_interface_table_name(interface_name)
if table_name == "":
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan/Loopback]")
interface_addresses = get_interface_ipaddresses(config_db, interface_name)
# If we deleting the last IP entry of the interface, check whether a static route present for the RIF
# before deleting the entry and also the RIF.
if interface_addresses == {ip_address}:
# Check both IPv4 and IPv6 routes.
ip_versions = [ "ip", "ipv6"]
for ip_ver in ip_versions:
# Compete the command and ask Zebra to return the routes.
# Scopes of all VRFs will be checked.
cmd = "show {} route vrf all static".format(ip_ver)
if multi_asic.is_multi_asic():
output = bgp_util.run_bgp_command(cmd, ctx.obj['namespace'])
else:
output = bgp_util.run_bgp_command(cmd)
# If there is output data, check is there a static route,
# bound to the interface.
if output != "":
if any(interface_name in output_line for output_line in output.splitlines()):
ctx.fail("Cannot remove the last IP entry of interface {}. A static {} route is still bound to the RIF.".format(interface_name, ip_ver))
remove_router_interface_ip_address(config_db, interface_name, ip_address)
interface_addresses = get_interface_ipaddresses(config_db, interface_name)
if len(interface_addresses) == 0 and is_interface_bind_to_vrf(config_db, interface_name) is False and get_intf_ipv6_link_local_mode(ctx, interface_name, table_name) != "enable":
config_db.set_entry(table_name, interface_name, None)
if multi_asic.is_multi_asic():
command = "sudo ip netns exec {} ip neigh flush dev {} {}".format(ctx.obj['namespace'], interface_name, str(ip_address))
else:
command = "ip neigh flush dev {} {}".format(interface_name, str(ip_address))
clicommon.run_command(command)
#
# buffer commands and utilities
#
def buffer_objects_map_check_legality(ctx, db, interface_name, input_map, is_new_id, is_pg):
"""
Tool function to check whether input_map is legal.
Three checking performed:
1. Whether the input_map is legal: pgs are in range [0-7]
2. Whether the input_map overlaps an existing pg in the port
"""
def _parse_object_id(idsmap):
"""
Tool function to parse the idsmap
Args:
idsmap: string containing object IDs map, like 3-4 or 7
Return:
The upper and lower bound. In case the idsmap is illegal, it returns None, None
Example:
3-4 => 3, 4
7 => 7
3- => None, None
"""
try:
match = re.search("^([0-9]+)(-[0-9]+)?$", idsmap)
lower = int(match.group(1))
if match.group(2):
upper = int(match.group(2)[1:])
else:
upper = lower
except Exception:
lower, upper = None, None
return lower, upper
config_db = db.cfgdb
object_name = "priority group" if is_pg else "queue"
try:
# Fetch maximum object id from STATE_DB
state_db = db.db
field_name = 'max_priority_groups' if is_pg else 'max_queues'
_hash = 'BUFFER_MAX_PARAM_TABLE|{}'.format(interface_name)
buffer_max_params = state_db.get_all(state_db.STATE_DB, _hash)
maximum_id = int(buffer_max_params.get(field_name)) - 1
except Exception:
ctx.fail("Unable to fetch {} from {} in STATE_DB".format(field_name, _hash))
lower, upper = _parse_object_id(input_map)
if not upper or not lower or upper < lower or lower < 0 or upper > maximum_id:
ctx.fail("Buffer {} {} is not valid.".format(object_name, input_map))
# Check overlapping.
# To configure a new PG which is overlapping an existing one is not allowed
# For example, to add '5-6' while '3-5' existing is illegal
existing_object_maps = config_db.get_table("BUFFER_PG" if is_pg else "BUFFER_QUEUE")
if not is_new_id:
if not (interface_name, input_map) in existing_object_maps.keys():
ctx.fail("Buffer {} {} doesn't exist".format(object_name, input_map))
return
for k, v in existing_object_maps.items():
port, existing_object_map = k
if port == interface_name:
existing_lower, existing_upper = _parse_object_id(existing_object_map)
if existing_upper < lower or existing_lower > upper:
# new and existing pgs disjoint, legal
pass
else:
ctx.fail("Buffer {} {} overlaps with existing {} {}".format(object_name, input_map, object_name, existing_object_map))
def update_buffer_object(db, interface_name, object_map, override_profile, is_pg, add=True):
config_db = db.cfgdb
ctx = click.get_current_context()
# Check whether port is legal
ports = config_db.get_entry("PORT", interface_name)
if not ports:
ctx.fail("Port {} doesn't exist".format(interface_name))
buffer_table = "BUFFER_PG" if is_pg else "BUFFER_QUEUE"
# Check whether object_map is legal
# Check whether there is other lossless profiles configured on the interface
buffer_objects_map_check_legality(ctx, db, interface_name, object_map, add, is_pg)
# All checking passed
if override_profile:
profile_dict = config_db.get_entry("BUFFER_PROFILE", override_profile)
if not profile_dict:
ctx.fail("Profile {} doesn't exist".format(override_profile))
pool_name = profile_dict.get("pool")
if not pool_name:
ctx.fail("Profile {} is invalid".format(override_profile))
pool_dict = config_db.get_entry("BUFFER_POOL", pool_name)
pool_dir = pool_dict.get("type")
expected_dir = "ingress" if is_pg else "egress"
if pool_dir != expected_dir:
ctx.fail("Type of pool {} referenced by profile {} is wrong".format(pool_name, override_profile))
if is_pg:
if not 'xoff' in profile_dict.keys() and 'size' in profile_dict.keys():
ctx.fail("Profile {} doesn't exist or isn't a lossless profile".format(override_profile))
config_db.set_entry(buffer_table, (interface_name, object_map), {"profile": override_profile})
else:
config_db.set_entry(buffer_table, (interface_name, object_map), {"profile": "NULL"})
if is_pg:
adjust_pfc_enable(ctx, db, interface_name, object_map, True)
def remove_buffer_object_on_port(db, interface_name, buffer_object_map, is_pg=True):
config_db = db.cfgdb
ctx = click.get_current_context()
# Check whether port is legal
ports = config_db.get_entry("PORT", interface_name)
if not ports:
ctx.fail("Port {} doesn't exist".format(interface_name))
# Remvoe all dynamic lossless PGs on the port
buffer_table = "BUFFER_PG" if is_pg else "BUFFER_QUEUE"
existing_buffer_objects = config_db.get_table(buffer_table)
removed = False
for k, v in existing_buffer_objects.items():
port, existing_buffer_object = k
if port == interface_name and (not buffer_object_map or buffer_object_map == existing_buffer_object):
referenced_profile = v.get('profile')
if referenced_profile and referenced_profile == 'ingress_lossy_profile':
if buffer_object_map:
ctx.fail("Lossy PG {} can't be removed".format(buffer_object_map))
else:
continue
config_db.set_entry(buffer_table, (interface_name, existing_buffer_object), None)
if is_pg:
adjust_pfc_enable(ctx, db, interface_name, buffer_object_map, False)
removed = True
if not removed:
object_name = "lossless priority group" if is_pg else "queue"
if buffer_object_map:
ctx.fail("No specified {} {} found on port {}".format(object_name, buffer_object_map, interface_name))
else:
ctx.fail("No {} found on port {}".format(object_name, interface_name))
def adjust_pfc_enable(ctx, db, interface_name, pg_map, add):
config_db = db.cfgdb
# Fetch the original pfc_enable
qosmap = config_db.get_entry("PORT_QOS_MAP", interface_name)
pfc_enable = qosmap.get("pfc_enable")
pfc_set = set()
if pfc_enable:
for priority in pfc_enable.split(","):
pfc_set.add(int(priority))
if pg_map:
lower_bound = int(pg_map[0])
upper_bound = int(pg_map[-1])
for priority in range(lower_bound, upper_bound + 1):
if add:
pfc_set.add(priority)
elif priority in pfc_set:
pfc_set.remove(priority)
empty_set = set()
pfc_enable = ""
if not pfc_set.issubset(empty_set):
for priority in pfc_set:
pfc_enable += str(priority) + ","
elif not add:
# Remove all
pfc_enable = ""
else:
ctx.fail("Try to add empty priorities")
qosmap["pfc_enable"] = pfc_enable[:-1]
config_db.set_entry("PORT_QOS_MAP", interface_name, qosmap)
#
# 'buffer' subgroup ('config interface buffer ...')
#
@interface.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def buffer(ctx):
"""Set or clear buffer configuration"""
config_db = ctx.obj["config_db"]
if not is_dynamic_buffer_enabled(config_db):
ctx.fail("This command can only be executed on a system with dynamic buffer enabled")
#
# 'priority_group' subgroup ('config interface buffer priority_group ...')
#
@buffer.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def priority_group(ctx):
"""Set or clear buffer configuration"""
pass
#
# 'lossless' subgroup ('config interface buffer priority_group lossless ...')
#
@priority_group.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def lossless(ctx):
"""Set or clear lossless PGs"""
pass
#
# 'add' subcommand
#
@lossless.command('add')
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('pg_map', metavar='<pg_map>', required=True)
@click.argument('override_profile', metavar='<override_profile>', required=False)
@clicommon.pass_db
def add_pg(db, interface_name, pg_map, override_profile):
"""Set lossless PGs for the interface"""
update_buffer_object(db, interface_name, pg_map, override_profile, True)
#
# 'set' subcommand
#
@lossless.command('set')
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('pg_map', metavar='<pg_map>', required=True)
@click.argument('override_profile', metavar='<override_profile>', required=False)
@clicommon.pass_db
def set_pg(db, interface_name, pg_map, override_profile):
"""Set lossless PGs for the interface"""
update_buffer_object(db, interface_name, pg_map, override_profile, True, False)
#
# 'remove' subcommand
#
@lossless.command('remove')
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('pg_map', metavar='<pg_map', required=False)
@clicommon.pass_db
def remove_pg(db, interface_name, pg_map):
"""Clear lossless PGs for the interface"""
remove_buffer_object_on_port(db, interface_name, pg_map)
#
# 'queue' subgroup ('config interface buffer queue ...')
#
@buffer.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def queue(ctx):
"""Set or clear buffer configuration"""
pass
#
# 'add' subcommand
#
@queue.command('add')
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('queue_map', metavar='<queue_map>', required=True)
@click.argument('buffer_profile', metavar='<buffer_profile>', required=True)
@clicommon.pass_db
def add_queue(db, interface_name, queue_map, buffer_profile):
"""Set lossless QUEUEs for the interface"""
update_buffer_object(db, interface_name, queue_map, buffer_profile, False)
#
# 'set' subcommand
#
@queue.command('set')
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('queue_map', metavar='<queue_map>', required=True)
@click.argument('buffer_profile', metavar='<buffer_profile>', required=True)
@clicommon.pass_db
def set_queue(db, interface_name, queue_map, buffer_profile):
"""Set lossless QUEUEs for the interface"""
update_buffer_object(db, interface_name, queue_map, buffer_profile, False, False)
#
# 'remove' subcommand
#
@queue.command('remove')
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('queue_map', metavar='<queue_map>', required=False)
@clicommon.pass_db
def remove_queue(db, interface_name, queue_map):
"""Clear lossless QUEUEs for the interface"""
remove_buffer_object_on_port(db, interface_name, queue_map, False)
#
# 'cable_length' subcommand
#
@interface.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('length', metavar='<length>', required=True)
@click.pass_context
def cable_length(ctx, interface_name, length):
"""Set interface cable length"""
config_db = ctx.obj["config_db"]
if not is_dynamic_buffer_enabled(config_db):
ctx.fail("This command can only be supported on a system with dynamic buffer enabled")
# Check whether port is legal
ports = config_db.get_entry("PORT", interface_name)
if not ports:
ctx.fail("Port {} doesn't exist".format(interface_name))
try:
assert "m" == length[-1]
except Exception:
ctx.fail("Invalid cable length. Should be in format <num>m, like 300m".format(cable_length))
keys = config_db.get_keys("CABLE_LENGTH")
cable_length_set = {}
cable_length_set[interface_name] = length
config_db.mod_entry("CABLE_LENGTH", keys[0], cable_length_set)
#
# 'transceiver' subgroup ('config interface transceiver ...')
#
@interface.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def transceiver(ctx):
"""SFP transceiver configuration"""
pass
#
# 'lpmode' subcommand ('config interface transceiver lpmode ...')
#
@transceiver.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('state', metavar='(enable|disable)', type=click.Choice(['enable', 'disable']))
@click.pass_context
def lpmode(ctx, interface_name, state):
"""Enable/disable low-power mode for SFP transceiver module"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
if interface_name_is_valid(config_db, interface_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
cmd = "sudo sfputil lpmode {} {}".format("on" if state == "enable" else "off", interface_name)
clicommon.run_command(cmd)
#
# 'reset' subcommand ('config interface reset ...')
#
@transceiver.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.pass_context
def reset(ctx, interface_name):
"""Reset SFP transceiver module"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
if interface_name_is_valid(config_db, interface_name) is False:
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
cmd = "sudo sfputil reset {}".format(interface_name)
clicommon.run_command(cmd)
#
# 'mpls' subgroup ('config interface mpls ...')
#
@interface.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def mpls(ctx):
"""Add or remove MPLS"""
pass
#
# 'add' subcommand
#
@mpls.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.pass_context
def add(ctx, interface_name):
"""Add MPLS operation on the interface"""
config_db = ctx.obj["config_db"]
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
table_name = get_interface_table_name(interface_name)
if not clicommon.is_interface_in_config_db(config_db, interface_name):
ctx.fail('interface {} doesn`t exist'.format(interface_name))
if table_name == "":
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan]")
config_db.set_entry(table_name, interface_name, {"mpls": "enable"})
#
# 'remove' subcommand
#
@mpls.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.pass_context
def remove(ctx, interface_name):
"""Remove MPLS operation from the interface"""
config_db = ctx.obj["config_db"]
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
table_name = get_interface_table_name(interface_name)
if not clicommon.is_interface_in_config_db(config_db, interface_name):
ctx.fail('interface {} doesn`t exist'.format(interface_name))
if table_name == "":
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan]")
config_db.set_entry(table_name, interface_name, {"mpls": "disable"})
#
# 'vrf' subgroup ('config interface vrf ...')
#
@interface.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def vrf(ctx):
"""Bind or unbind VRF"""
pass
#
# 'bind' subcommand
#
@vrf.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('vrf_name', metavar='<vrf_name>', required=True)
@click.pass_context
def bind(ctx, interface_name, vrf_name):
"""Bind the interface to VRF"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
table_name = get_interface_table_name(interface_name)
if table_name == "":
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan/Loopback]")
if is_interface_bind_to_vrf(config_db, interface_name) is True and \
config_db.get_entry(table_name, interface_name).get('vrf_name') == vrf_name:
return
# Clean ip addresses if interface configured
interface_addresses = get_interface_ipaddresses(config_db, interface_name)
for ipaddress in interface_addresses:
remove_router_interface_ip_address(config_db, interface_name, ipaddress)
config_db.set_entry(table_name, interface_name, None)
# When config_db del entry and then add entry with same key, the DEL will lost.
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
state_db = SonicV2Connector(use_unix_socket_path=True)
else:
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=ctx.obj['namespace'])
state_db.connect(state_db.STATE_DB, False)
_hash = '{}{}'.format('INTERFACE_TABLE|', interface_name)
while state_db.exists(state_db.STATE_DB, _hash):
time.sleep(0.01)
state_db.close(state_db.STATE_DB)
config_db.set_entry(table_name, interface_name, {"vrf_name": vrf_name})
#
# 'unbind' subcommand
#
@vrf.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.pass_context
def unbind(ctx, interface_name):
"""Unbind the interface to VRF"""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("interface is None!")
table_name = get_interface_table_name(interface_name)
if table_name == "":
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan/Loopback]")
if is_interface_bind_to_vrf(config_db, interface_name) is False:
return
interface_ipaddresses = get_interface_ipaddresses(config_db, interface_name)
for ipaddress in interface_ipaddresses:
remove_router_interface_ip_address(config_db, interface_name, ipaddress)
config_db.set_entry(table_name, interface_name, None)
#
# 'ipv6' subgroup ('config interface ipv6 ...')
#
@interface.group()
@click.pass_context
def ipv6(ctx):
"""Enable or Disable IPv6 processing on interface"""
pass
@ipv6.group('enable')
def enable():
"""Enable IPv6 processing on interface"""
pass
@ipv6.group('disable')
def disable():
"""Disble IPv6 processing on interface"""
pass
#
# 'config interface ipv6 enable use-link-local-only <interface-name>'
#
@enable.command('use-link-local-only')
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
def enable_use_link_local_only(ctx, interface_name):
"""Enable IPv6 link local address on interface"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {}
ctx.obj['config_db'] = config_db
db = ctx.obj["config_db"]
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
if interface_name.startswith("Ethernet"):
interface_type = "INTERFACE"
elif interface_name.startswith("PortChannel"):
interface_type = "PORTCHANNEL_INTERFACE"
elif interface_name.startswith("Vlan"):
interface_type = "VLAN_INTERFACE"
else:
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan]")
if (interface_type == "INTERFACE" ) or (interface_type == "PORTCHANNEL_INTERFACE"):
if interface_name_is_valid(db, interface_name) is False:
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))
if (interface_type == "VLAN_INTERFACE"):
if not clicommon.is_valid_vlan_interface(db, interface_name):
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))
portchannel_member_table = db.get_table('PORTCHANNEL_MEMBER')
if interface_is_in_portchannel(portchannel_member_table, interface_name):
ctx.fail("{} is configured as a member of portchannel. Cannot configure the IPv6 link local mode!"
.format(interface_name))
vlan_member_table = db.get_table('VLAN_MEMBER')
if interface_is_in_vlan(vlan_member_table, interface_name):
ctx.fail("{} is configured as a member of vlan. Cannot configure the IPv6 link local mode!"
.format(interface_name))
interface_dict = db.get_table(interface_type)
set_ipv6_link_local_only_on_interface(db, interface_dict, interface_type, interface_name, "enable")
#
# 'config interface ipv6 disable use-link-local-only <interface-name>'
#
@disable.command('use-link-local-only')
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
def disable_use_link_local_only(ctx, interface_name):
"""Disable IPv6 link local address on interface"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {}
ctx.obj['config_db'] = config_db
db = ctx.obj["config_db"]
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
interface_type = ""
if interface_name.startswith("Ethernet"):
interface_type = "INTERFACE"
elif interface_name.startswith("PortChannel"):
interface_type = "PORTCHANNEL_INTERFACE"
elif interface_name.startswith("Vlan"):
interface_type = "VLAN_INTERFACE"
else:
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan]")
if (interface_type == "INTERFACE" ) or (interface_type == "PORTCHANNEL_INTERFACE"):
if interface_name_is_valid(db, interface_name) is False:
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))
if (interface_type == "VLAN_INTERFACE"):
if not clicommon.is_valid_vlan_interface(db, interface_name):
ctx.fail("Interface name %s is invalid. Please enter a valid interface name!!" %(interface_name))
portchannel_member_table = db.get_table('PORTCHANNEL_MEMBER')
if interface_is_in_portchannel(portchannel_member_table, interface_name):
ctx.fail("{} is configured as a member of portchannel. Cannot configure the IPv6 link local mode!"
.format(interface_name))
vlan_member_table = db.get_table('VLAN_MEMBER')
if interface_is_in_vlan(vlan_member_table, interface_name):
ctx.fail("{} is configured as a member of vlan. Cannot configure the IPv6 link local mode!"
.format(interface_name))
interface_dict = db.get_table(interface_type)
set_ipv6_link_local_only_on_interface(db, interface_dict, interface_type, interface_name, "disable")
#
# 'vrf' group ('config vrf ...')
#
@config.group(cls=clicommon.AbbreviationGroup, name='vrf')
@click.pass_context
def vrf(ctx):
"""VRF-related configuration tasks"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {}
ctx.obj['config_db'] = config_db
@vrf.command('add')
@click.argument('vrf_name', metavar='<vrf_name>', required=True)
@click.pass_context
def add_vrf(ctx, vrf_name):
"""Add vrf"""
config_db = ctx.obj['config_db']
if not vrf_name.startswith("Vrf") and not (vrf_name == 'mgmt') and not (vrf_name == 'management'):
ctx.fail("'vrf_name' is not start with Vrf, mgmt or management!")
if len(vrf_name) > 15:
ctx.fail("'vrf_name' is too long!")
if (vrf_name == 'mgmt' or vrf_name == 'management'):
vrf_add_management_vrf(config_db)
else:
config_db.set_entry('VRF', vrf_name, {"NULL": "NULL"})
@vrf.command('del')
@click.argument('vrf_name', metavar='<vrf_name>', required=True)
@click.pass_context
def del_vrf(ctx, vrf_name):
"""Del vrf"""
config_db = ctx.obj['config_db']
if not vrf_name.startswith("Vrf") and not (vrf_name == 'mgmt') and not (vrf_name == 'management'):
ctx.fail("'vrf_name' is not start with Vrf, mgmt or management!")
if len(vrf_name) > 15:
ctx.fail("'vrf_name' is too long!")
if (vrf_name == 'mgmt' or vrf_name == 'management'):
vrf_delete_management_vrf(config_db)
else:
del_interface_bind_to_vrf(config_db, vrf_name)
config_db.set_entry('VRF', vrf_name, None)
@vrf.command('add_vrf_vni_map')
@click.argument('vrfname', metavar='<vrf-name>', required=True, type=str)
@click.argument('vni', metavar='<vni>', required=True)
@click.pass_context
def add_vrf_vni_map(ctx, vrfname, vni):
config_db = ctx.obj['config_db']
found = 0
if vrfname not in config_db.get_table('VRF').keys():
ctx.fail("vrf {} doesnt exists".format(vrfname))
if not vni.isdigit():
ctx.fail("Invalid VNI {}. Only valid VNI is accepted".format(vni))
if clicommon.vni_id_is_valid(int(vni)) is False:
ctx.fail("Invalid VNI {}. Valid range [1 to 16777215].".format(vni))
vxlan_table = config_db.get_table('VXLAN_TUNNEL_MAP')
vxlan_keys = vxlan_table.keys()
if vxlan_keys is not None:
for key in vxlan_keys:
if (vxlan_table[key]['vni'] == vni):
found = 1
break
if (found == 0):
ctx.fail("VLAN VNI not mapped. Please create VLAN VNI map entry first")
found = 0
vrf_table = config_db.get_table('VRF')
vrf_keys = vrf_table.keys()
if vrf_keys is not None:
for vrf_key in vrf_keys:
if ('vni' in vrf_table[vrf_key] and vrf_table[vrf_key]['vni'] == vni):
found = 1
break
if (found == 1):
ctx.fail("VNI already mapped to vrf {}".format(vrf_key))
config_db.mod_entry('VRF', vrfname, {"vni": vni})
@vrf.command('del_vrf_vni_map')
@click.argument('vrfname', metavar='<vrf-name>', required=True, type=str)
@click.pass_context
def del_vrf_vni_map(ctx, vrfname):
config_db = ctx.obj['config_db']
if vrfname not in config_db.get_table('VRF').keys():
ctx.fail("vrf {} doesnt exists".format(vrfname))
config_db.mod_entry('VRF', vrfname, {"vni": 0})
#
# 'route' group ('config route ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def route(ctx):
"""route-related configuration tasks"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {}
ctx.obj['config_db'] = config_db
@route.command('add', context_settings={"ignore_unknown_options": True})
@click.argument('command_str', metavar='prefix [vrf <vrf_name>] <A.B.C.D/M> nexthop <[vrf <vrf_name>] <A.B.C.D>>|<dev <dev_name>>', nargs=-1, type=click.Path())
@click.pass_context
def add_route(ctx, command_str):
"""Add route command"""
config_db = ctx.obj['config_db']
key, route = cli_sroute_to_config(ctx, command_str)
# If defined intf name, check if it belongs to interface
if 'ifname' in route:
if (not route['ifname'] in config_db.get_keys('VLAN_INTERFACE') and
not route['ifname'] in config_db.get_keys('INTERFACE') and
not route['ifname'] in config_db.get_keys('PORTCHANNEL_INTERFACE') and
not route['ifname'] == 'null'):
ctx.fail('interface {} doesn`t exist'.format(route['ifname']))
entry_counter = 1
if 'nexthop' in route:
entry_counter = len(route['nexthop'].split(','))
# Alignment in case the command contains several nexthop ip
for i in range(entry_counter):
if 'nexthop-vrf' in route:
if i > 0:
vrf = route['nexthop-vrf'].split(',')[0]
route['nexthop-vrf'] += ',' + vrf
else:
route['nexthop-vrf'] = ''
if not 'nexthop' in route:
route['nexthop'] = ''
if 'ifname' in route:
if i > 0:
route['ifname'] += ','
else:
route['ifname'] = ''
# Set default values for distance and blackhole because the command doesn't have such an option
if 'distance' in route:
route['distance'] += ',0'
else:
route['distance'] = '0'
if 'blackhole' in route:
route['blackhole'] += ',false'
else:
# If the user configure with "ifname" as "null", set 'blackhole' attribute as true.
if 'ifname' in route and route['ifname'] == 'null':
route['blackhole'] = 'true'
else:
route['blackhole'] = 'false'
# Check if exist entry with key
keys = config_db.get_keys('STATIC_ROUTE')
if key in keys:
# If exist update current entry
current_entry = config_db.get_entry('STATIC_ROUTE', key)
for entry in ['nexthop', 'nexthop-vrf', 'ifname', 'distance', 'blackhole']:
if not entry in current_entry:
current_entry[entry] = ''
if entry in route:
current_entry[entry] += ',' + route[entry]
else:
current_entry[entry] += ','
config_db.set_entry("STATIC_ROUTE", key, current_entry)
else:
config_db.set_entry("STATIC_ROUTE", key, route)
@route.command('del', context_settings={"ignore_unknown_options": True})
@click.argument('command_str', metavar='prefix [vrf <vrf_name>] <A.B.C.D/M> nexthop <[vrf <vrf_name>] <A.B.C.D>>|<dev <dev_name>>', nargs=-1, type=click.Path())
@click.pass_context
def del_route(ctx, command_str):
"""Del route command"""
config_db = ctx.obj['config_db']
key, route = cli_sroute_to_config(ctx, command_str, strict_nh=False)
keys = config_db.get_keys('STATIC_ROUTE')
prefix_tuple = tuple(key.split('|'))
if not key in keys and not prefix_tuple in keys:
ctx.fail('Route {} doesnt exist'.format(key))
else:
# If not defined nexthop or intf name remove entire route
if not 'nexthop' in route and not 'ifname' in route:
config_db.set_entry("STATIC_ROUTE", key, None)
return
current_entry = config_db.get_entry('STATIC_ROUTE', key)
nh = ['']
nh_vrf = ['']
ifname = ['']
distance = ['']
blackhole = ['']
if 'nexthop' in current_entry:
nh = current_entry['nexthop'].split(',')
if 'nexthop-vrf' in current_entry:
nh_vrf = current_entry['nexthop-vrf'].split(',')
if 'ifname' in current_entry:
ifname = current_entry['ifname'].split(',')
if 'distance' in current_entry:
distance = current_entry['distance'].split(',')
if 'blackhole' in current_entry:
blackhole = current_entry['blackhole'].split(',')
# Zip data from config_db into tuples
# {'nexthop': '10.0.0.2,192.168.3.11', 'vrf-nexthop': ',Vrf-RED', 'ifname': ','}
# [('10.0.0.2', '', ''), ('192.168.3.11', 'Vrf-RED', '')]
nh_zip = list(itertools.zip_longest(nh, nh_vrf, ifname, fillvalue=''))
cli_tuple = ()
# Create tuple from CLI argument
# config route add prefix 1.4.3.4/32 nexthop vrf Vrf-RED 192.168.3.11
# ('192.168.3.11', 'Vrf-RED', '')
for entry in ['nexthop', 'nexthop-vrf', 'ifname']:
if entry in route:
cli_tuple += (route[entry],)
else:
cli_tuple += ('',)
if cli_tuple in nh_zip:
# If cli tuple is in config_db find its index and delete from lists
idx = nh_zip.index(cli_tuple)
if len(nh) - 1 >= idx:
del nh[idx]
if len(nh_vrf) - 1 >= idx:
del nh_vrf[idx]
if len(ifname) - 1 >= idx:
del ifname[idx]
if len(distance) - 1 >= idx:
del distance[idx]
if len(blackhole) - 1 >= idx:
del blackhole[idx]
else:
ctx.fail('Not found {} in {}'.format(cli_tuple, key))
if (len(nh) == 0 or (len(nh) == 1 and nh[0] == '')) and \
(len(ifname) == 0 or (len(ifname) == 1 and ifname[0] == '')):
# If there are no nexthop and ifname fields in the current record, delete it
config_db.set_entry("STATIC_ROUTE", key, None)
else:
# Otherwise it still has ECMP nexthop or ifname fields, so compose it from the lists into db
current_entry['nexthop'] = ','.join((str(e)) for e in nh)
current_entry['nexthop-vrf'] = ','.join((str(e)) for e in nh_vrf)
current_entry['ifname'] = ','.join((str(e)) for e in ifname)
current_entry['distance'] = ','.join((str(e)) for e in distance)
current_entry['blackhole'] = ','.join((str(e)) for e in blackhole)
config_db.set_entry("STATIC_ROUTE", key, current_entry)
#
# 'acl' group ('config acl ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
def acl():
"""ACL-related configuration tasks"""
pass
#
# 'add' subgroup ('config acl add ...')
#
@acl.group(cls=clicommon.AbbreviationGroup)
def add():
"""
Add ACL configuration.
"""
pass
def get_acl_bound_ports():
config_db = ConfigDBConnector()
config_db.connect()
ports = set()
portchannel_members = set()
portchannel_member_dict = config_db.get_table("PORTCHANNEL_MEMBER")
for key in portchannel_member_dict:
ports.add(key[0])
portchannel_members.add(key[1])
port_dict = config_db.get_table("PORT")
for key in port_dict:
if key not in portchannel_members:
ports.add(key)
return list(ports)
def expand_vlan_ports(port_name):
"""
Expands a given VLAN interface into its member ports.
If the provided interface is a VLAN, then this method will return its member ports.
If the provided interface is not a VLAN, then this method will return a list with only
the provided interface in it.
"""
config_db = ConfigDBConnector()
config_db.connect()
if port_name not in config_db.get_keys("VLAN"):
return [port_name]
vlan_members = config_db.get_keys("VLAN_MEMBER")
members = [member for vlan, member in vlan_members if port_name == vlan]
if not members:
raise ValueError("Cannot bind empty VLAN {}".format(port_name))
return members
def parse_acl_table_info(table_name, table_type, description, ports, stage):
table_info = {"type": table_type}
if description:
table_info["policy_desc"] = description
else:
table_info["policy_desc"] = table_name
if not ports and ports != None:
raise ValueError("Cannot bind empty list of ports")
port_list = []
valid_acl_ports = get_acl_bound_ports()
if ports:
for port in ports.split(","):
port_list += expand_vlan_ports(port)
port_list = list(set(port_list)) # convert to set first to remove duplicate ifaces
else:
port_list = valid_acl_ports
for port in port_list:
if port not in valid_acl_ports:
raise ValueError("Cannot bind ACL to specified port {}".format(port))
table_info["ports"] = port_list
table_info["stage"] = stage
return table_info
#
# 'table' subcommand ('config acl add table ...')
#
@add.command()
@click.argument("table_name", metavar="<table_name>")
@click.argument("table_type", metavar="<table_type>")
@click.option("-d", "--description")
@click.option("-p", "--ports")
@click.option("-s", "--stage", type=click.Choice(["ingress", "egress"]), default="ingress")
@click.pass_context
def table(ctx, table_name, table_type, description, ports, stage):
"""
Add ACL table
"""
config_db = ConfigDBConnector()
config_db.connect()
try:
table_info = parse_acl_table_info(table_name, table_type, description, ports, stage)
except ValueError as e:
ctx.fail("Failed to parse ACL table config: exception={}".format(e))
config_db.set_entry("ACL_TABLE", table_name, table_info)
#
# 'remove' subgroup ('config acl remove ...')
#
@acl.group(cls=clicommon.AbbreviationGroup)
def remove():
"""
Remove ACL configuration.
"""
pass
#
# 'table' subcommand ('config acl remove table ...')
#
@remove.command()
@click.argument("table_name", metavar="<table_name>")
def table(table_name):
"""
Remove ACL table
"""
config_db = ConfigDBConnector()
config_db.connect()
config_db.set_entry("ACL_TABLE", table_name, None)
#
# 'acl update' group
#
@acl.group(cls=clicommon.AbbreviationGroup)
def update():
"""ACL-related configuration tasks"""
pass
#
# 'full' subcommand
#
@update.command()
@click.argument('file_name', required=True)
def full(file_name):
"""Full update of ACL rules configuration."""
log.log_info("'acl update full {}' executing...".format(file_name))
command = "acl-loader update full {}".format(file_name)
clicommon.run_command(command)
#
# 'incremental' subcommand
#
@update.command()
@click.argument('file_name', required=True)
def incremental(file_name):
"""Incremental update of ACL rule configuration."""
log.log_info("'acl update incremental {}' executing...".format(file_name))
command = "acl-loader update incremental {}".format(file_name)
clicommon.run_command(command)
#
# 'dropcounters' group ('config dropcounters ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
def dropcounters():
"""Drop counter related configuration tasks"""
pass
#
# 'install' subcommand ('config dropcounters install')
#
@dropcounters.command()
@click.argument("counter_name", type=str, required=True)
@click.argument("counter_type", type=str, required=True)
@click.argument("reasons", type=str, required=True)
@click.option("-a", "--alias", type=str, help="Alias for this counter")
@click.option("-g", "--group", type=str, help="Group for this counter")
@click.option("-d", "--desc", type=str, help="Description for this counter")
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def install(counter_name, alias, group, counter_type, desc, reasons, verbose):
"""Install a new drop counter"""
command = "dropconfig -c install -n '{}' -t '{}' -r '{}'".format(counter_name, counter_type, reasons)
if alias:
command += " -a '{}'".format(alias)
if group:
command += " -g '{}'".format(group)
if desc:
command += " -d '{}'".format(desc)
clicommon.run_command(command, display_cmd=verbose)
#
# 'delete' subcommand ('config dropcounters delete')
#
@dropcounters.command()
@click.argument("counter_name", type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def delete(counter_name, verbose):
"""Delete an existing drop counter"""
command = "dropconfig -c uninstall -n {}".format(counter_name)
clicommon.run_command(command, display_cmd=verbose)
#
# 'add_reasons' subcommand ('config dropcounters add_reasons')
#
@dropcounters.command('add-reasons')
@click.argument("counter_name", type=str, required=True)
@click.argument("reasons", type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def add_reasons(counter_name, reasons, verbose):
"""Add reasons to an existing drop counter"""
command = "dropconfig -c add -n {} -r {}".format(counter_name, reasons)
clicommon.run_command(command, display_cmd=verbose)
#
# 'remove_reasons' subcommand ('config dropcounters remove_reasons')
#
@dropcounters.command('remove-reasons')
@click.argument("counter_name", type=str, required=True)
@click.argument("reasons", type=str, required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def remove_reasons(counter_name, reasons, verbose):
"""Remove reasons from an existing drop counter"""
command = "dropconfig -c remove -n {} -r {}".format(counter_name, reasons)
clicommon.run_command(command, display_cmd=verbose)
#
# 'ecn' command ('config ecn ...')
#
@config.command()
@click.option('-profile', metavar='<profile_name>', type=str, required=True, help="Profile name")
@click.option('-rmax', metavar='<red threshold max>', type=int, help="Set red max threshold")
@click.option('-rmin', metavar='<red threshold min>', type=int, help="Set red min threshold")
@click.option('-ymax', metavar='<yellow threshold max>', type=int, help="Set yellow max threshold")
@click.option('-ymin', metavar='<yellow threshold min>', type=int, help="Set yellow min threshold")
@click.option('-gmax', metavar='<green threshold max>', type=int, help="Set green max threshold")
@click.option('-gmin', metavar='<green threshold min>', type=int, help="Set green min threshold")
@click.option('-rdrop', metavar='<red drop probability>', type=click.IntRange(0, 100), help="Set red drop probability")
@click.option('-ydrop', metavar='<yellow drop probability>', type=click.IntRange(0, 100), help="Set yellow drop probability")
@click.option('-gdrop', metavar='<green drop probability>', type=click.IntRange(0, 100), help="Set green drop probability")
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def ecn(profile, rmax, rmin, ymax, ymin, gmax, gmin, rdrop, ydrop, gdrop, verbose):
"""ECN-related configuration tasks"""
log.log_info("'ecn -profile {}' executing...".format(profile))
command = "ecnconfig -p %s" % profile
if rmax is not None: command += " -rmax %d" % rmax
if rmin is not None: command += " -rmin %d" % rmin
if ymax is not None: command += " -ymax %d" % ymax
if ymin is not None: command += " -ymin %d" % ymin
if gmax is not None: command += " -gmax %d" % gmax
if gmin is not None: command += " -gmin %d" % gmin
if rdrop is not None: command += " -rdrop %d" % rdrop
if ydrop is not None: command += " -ydrop %d" % ydrop
if gdrop is not None: command += " -gdrop %d" % gdrop
if verbose: command += " -vv"
clicommon.run_command(command, display_cmd=verbose)
#
# 'pfc' group ('config interface pfc ...')
#
@interface.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def pfc(ctx):
"""Set PFC configuration."""
pass
#
# 'pfc asymmetric' ('config interface pfc asymmetric ...')
#
@pfc.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('status', type=click.Choice(['on', 'off']))
@click.pass_context
def asymmetric(ctx, interface_name, status):
"""Set asymmetric PFC configuration."""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
clicommon.run_command("pfc config asymmetric {0} {1}".format(status, interface_name))
#
# 'pfc priority' command ('config interface pfc priority ...')
#
@pfc.command()
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('priority', type=click.Choice([str(x) for x in range(8)]))
@click.argument('status', type=click.Choice(['on', 'off']))
@click.pass_context
def priority(ctx, interface_name, priority, status):
"""Set PFC priority configuration."""
# Get the config_db connector
config_db = ctx.obj['config_db']
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")
clicommon.run_command("pfc config priority {0} {1} {2}".format(status, interface_name, priority))
#
# 'buffer' group ('config buffer ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def buffer(ctx):
"""Configure buffer_profile"""
config_db = ConfigDBConnector()
config_db.connect()
if not is_dynamic_buffer_enabled(config_db):
ctx.fail("This command can only be supported on a system with dynamic buffer enabled")
@buffer.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def profile(ctx):
"""Configure buffer profile"""
pass
@profile.command('add')
@click.argument('profile', metavar='<profile>', required=True)
@click.option('--xon', metavar='<xon>', type=int, help="Set xon threshold")
@click.option('--xoff', metavar='<xoff>', type=int, help="Set xoff threshold")
@click.option('--size', metavar='<size>', type=int, help="Set reserved size size")
@click.option('--dynamic_th', metavar='<dynamic_th>', type=str, help="Set dynamic threshold")
@click.option('--pool', metavar='<pool>', type=str, help="Buffer pool")
@clicommon.pass_db
def add_profile(db, profile, xon, xoff, size, dynamic_th, pool):
"""Add or modify a buffer profile"""
config_db = db.cfgdb
ctx = click.get_current_context()
profile_entry = config_db.get_entry('BUFFER_PROFILE', profile)
if profile_entry:
ctx.fail("Profile {} already exist".format(profile))
update_profile(ctx, config_db, profile, xon, xoff, size, dynamic_th, pool)
@profile.command('set')
@click.argument('profile', metavar='<profile>', required=True)
@click.option('--xon', metavar='<xon>', type=int, help="Set xon threshold")
@click.option('--xoff', metavar='<xoff>', type=int, help="Set xoff threshold")
@click.option('--size', metavar='<size>', type=int, help="Set reserved size size")
@click.option('--dynamic_th', metavar='<dynamic_th>', type=str, help="Set dynamic threshold")
@click.option('--pool', metavar='<pool>', type=str, help="Buffer pool")
@clicommon.pass_db
def set_profile(db, profile, xon, xoff, size, dynamic_th, pool):
"""Add or modify a buffer profile"""
config_db = db.cfgdb
ctx = click.get_current_context()
profile_entry = config_db.get_entry('BUFFER_PROFILE', profile)
if not profile_entry:
ctx.fail("Profile {} doesn't exist".format(profile))
if not 'xoff' in profile_entry.keys() and xoff:
ctx.fail("Can't change profile {} from dynamically calculating headroom to non-dynamically one".format(profile))
update_profile(ctx, config_db, profile, xon, xoff, size, dynamic_th, pool, profile_entry)
def _is_shared_headroom_pool_enabled(ctx, config_db):
ingress_lossless_pool = config_db.get_entry('BUFFER_POOL', 'ingress_lossless_pool')
if 'xoff' in ingress_lossless_pool:
return True
default_lossless_param_table = config_db.get_table('DEFAULT_LOSSLESS_BUFFER_PARAMETER')
if not default_lossless_param_table:
ctx.fail("Dynamic buffer calculation is enabled while no entry found in DEFAULT_LOSSLESS_BUFFER_PARAMETER table")
default_lossless_param = list(default_lossless_param_table.values())[0]
over_subscribe_ratio = default_lossless_param.get('over_subscribe_ratio')
if over_subscribe_ratio and over_subscribe_ratio != '0':
return True
return False
def update_profile(ctx, config_db, profile_name, xon, xoff, size, dynamic_th, pool, profile_entry = None):
params = {}
if profile_entry:
params = profile_entry
shp_enabled = _is_shared_headroom_pool_enabled(ctx, config_db)
if not pool:
pool = 'ingress_lossless_pool'
params['pool'] = pool
if not config_db.get_entry('BUFFER_POOL', pool):
ctx.fail("Pool {} doesn't exist".format(pool))
if xon:
params['xon'] = xon
else:
xon = params.get('xon')
if xoff:
params['xoff'] = xoff
else:
xoff = params.get('xoff')
if size:
params['size'] = size
else:
size = params.get('size')
dynamic_calculate = False if (xon or xoff or size) else True
if dynamic_calculate:
params['headroom_type'] = 'dynamic'
if not dynamic_th:
ctx.fail("Either size information (xon, xoff, size) or dynamic_th needs to be provided")
params['dynamic_th'] = dynamic_th
else:
if not xon:
ctx.fail("Xon is mandatory for non-dynamic profile")
if not xoff:
if shp_enabled:
ctx.fail("Shared headroom pool is enabled, xoff is mandatory for non-dynamic profile")
elif not size:
ctx.fail("Neither xoff nor size is provided")
else:
xoff_number = int(size) - int(xon)
if xoff_number <= 0:
ctx.fail("The xoff must be greater than 0 while we got {} (calculated by: size {} - xon {})".format(xoff_number, size, xon))
params['xoff'] = str(xoff_number)
if not size:
if shp_enabled:
size = int(xon)
else:
size = int(xon) + int(xoff)
params['size'] = size
if dynamic_th:
params['dynamic_th'] = dynamic_th
elif not params.get('dynamic_th'):
# Fetch all the keys of default_lossless_buffer_parameter table
# and then get the default_dynamic_th from that entry (should be only one)
keys = config_db.get_keys('DEFAULT_LOSSLESS_BUFFER_PARAMETER')
if len(keys) != 1:
ctx.fail("Multiple entries are found in DEFAULT_LOSSLESS_BUFFER_PARAMETER while no dynamic_th specified")
default_lossless_param = config_db.get_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', keys[0])
if 'default_dynamic_th' in default_lossless_param:
params['dynamic_th'] = default_lossless_param['default_dynamic_th']
else:
ctx.fail("No dynamic_th defined in DEFAULT_LOSSLESS_BUFFER_PARAMETER")
config_db.set_entry("BUFFER_PROFILE", (profile_name), params)
@profile.command('remove')
@click.argument('profile', metavar='<profile>', required=True)
@clicommon.pass_db
def remove_profile(db, profile):
"""Delete a buffer profile"""
config_db = db.cfgdb
ctx = click.get_current_context()
existing_pgs = config_db.get_table("BUFFER_PG")
for k, v in existing_pgs.items():
port, pg = k
referenced_profile = v.get('profile')
if referenced_profile and referenced_profile == profile:
ctx.fail("Profile {} is referenced by {}|{} and can't be removed".format(profile, port, pg))
entry = config_db.get_entry("BUFFER_PROFILE", profile)
if entry:
config_db.set_entry("BUFFER_PROFILE", profile, None)
else:
ctx.fail("Profile {} doesn't exist".format(profile))
@buffer.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def shared_headroom_pool(ctx):
"""Configure buffer shared headroom pool"""
pass
@shared_headroom_pool.command()
@click.argument('ratio', metavar='<ratio>', type=int, required=True)
@clicommon.pass_db
def over_subscribe_ratio(db, ratio):
"""Configure over subscribe ratio"""
config_db = db.cfgdb
ctx = click.get_current_context()
port_number = len(config_db.get_table('PORT'))
if ratio < 0 or ratio > port_number:
ctx.fail("Invalid over-subscribe-ratio value {}. It should be in range [0, {}]".format(ratio, port_number))
default_lossless_param = config_db.get_table("DEFAULT_LOSSLESS_BUFFER_PARAMETER")
first_item = True
for k, v in default_lossless_param.items():
if not first_item:
ctx.fail("More than one item in DEFAULT_LOSSLESS_BUFFER_PARAMETER table. Only the first one is updated")
first_item = False
if ratio == 0:
if "over_subscribe_ratio" in v.keys():
v.pop("over_subscribe_ratio")
else:
v["over_subscribe_ratio"] = ratio
config_db.set_entry("DEFAULT_LOSSLESS_BUFFER_PARAMETER", k, v)
@shared_headroom_pool.command()
@click.argument('size', metavar='<size>', type=int, required=True)
@clicommon.pass_db
def size(db, size):
"""Configure shared headroom pool size"""
config_db = db.cfgdb
state_db = db.db
ctx = click.get_current_context()
_hash = 'BUFFER_MAX_PARAM_TABLE|global'
buffer_max_params = state_db.get_all(state_db.STATE_DB, _hash)
if buffer_max_params:
mmu_size = buffer_max_params.get('mmu_size')
if mmu_size and int(mmu_size) < size:
ctx.fail("Shared headroom pool must be less than mmu size ({})".format(mmu_size))
ingress_lossless_pool = config_db.get_entry("BUFFER_POOL", "ingress_lossless_pool")
if size == 0:
if "xoff" in ingress_lossless_pool:
ingress_lossless_pool.pop("xoff")
else:
ingress_lossless_pool["xoff"] = size
config_db.set_entry("BUFFER_POOL", "ingress_lossless_pool", ingress_lossless_pool)
#
# 'platform' group ('config platform ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
def platform():
"""Platform-related configuration tasks"""
# 'firmware' subgroup ("config platform firmware ...")
@platform.group(cls=clicommon.AbbreviationGroup)
def firmware():
"""Firmware configuration tasks"""
pass
# 'install' subcommand ("config platform firmware install")
@firmware.command(
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True
),
add_help_option=False
)
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
def install(args):
"""Install platform firmware"""
cmd = "fwutil install {}".format(" ".join(args))
try:
subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
# 'update' subcommand ("config platform firmware update")
@firmware.command(
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True
),
add_help_option=False
)
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
def update(args):
"""Update platform firmware"""
cmd = "fwutil update {}".format(" ".join(args))
try:
subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
#
# 'watermark' group ("show watermark telemetry interval")
#
@config.group(cls=clicommon.AbbreviationGroup)
def watermark():
"""Configure watermark """
pass
@watermark.group(cls=clicommon.AbbreviationGroup)
def telemetry():
"""Configure watermark telemetry"""
pass
@telemetry.command()
@click.argument('interval', required=True)
def interval(interval):
"""Configure watermark telemetry interval"""
command = 'watermarkcfg --config-interval ' + interval
clicommon.run_command(command)
#
# 'interface_naming_mode' subgroup ('config interface_naming_mode ...')
#
@config.group(cls=clicommon.AbbreviationGroup, name='interface_naming_mode')
def interface_naming_mode():
"""Modify interface naming mode for interacting with SONiC CLI"""
pass
@interface_naming_mode.command('default')
def naming_mode_default():
"""Set CLI interface naming mode to DEFAULT (SONiC port name)"""
set_interface_naming_mode('default')
@interface_naming_mode.command('alias')
def naming_mode_alias():
"""Set CLI interface naming mode to ALIAS (Vendor port alias)"""
set_interface_naming_mode('alias')
def is_loopback_name_valid(loopback_name):
"""Loopback name validation
"""
if loopback_name[:CFG_LOOPBACK_PREFIX_LEN] != CFG_LOOPBACK_PREFIX :
return False
if (loopback_name[CFG_LOOPBACK_PREFIX_LEN:].isdigit() is False or
int(loopback_name[CFG_LOOPBACK_PREFIX_LEN:]) > CFG_LOOPBACK_ID_MAX_VAL) :
return False
if len(loopback_name) > CFG_LOOPBACK_NAME_TOTAL_LEN_MAX:
return False
return True
#
# 'loopback' group ('config loopback ...')
#
@config.group()
@click.pass_context
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
def loopback(ctx, redis_unix_socket_path):
"""Loopback-related configuration tasks"""
kwargs = {}
if redis_unix_socket_path:
kwargs['unix_socket_path'] = redis_unix_socket_path
config_db = ConfigDBConnector(**kwargs)
config_db.connect(wait_for_init=False)
ctx.obj = {'db': config_db}
@loopback.command('add')
@click.argument('loopback_name', metavar='<loopback_name>', required=True)
@click.pass_context
def add_loopback(ctx, loopback_name):
config_db = ctx.obj['db']
if is_loopback_name_valid(loopback_name) is False:
ctx.fail("{} is invalid, name should have prefix '{}' and suffix '{}' "
.format(loopback_name, CFG_LOOPBACK_PREFIX, CFG_LOOPBACK_NO))
lo_intfs = [k for k, v in config_db.get_table('LOOPBACK_INTERFACE').items() if type(k) != tuple]
if loopback_name in lo_intfs:
ctx.fail("{} already exists".format(loopback_name))
config_db.set_entry('LOOPBACK_INTERFACE', loopback_name, {"NULL" : "NULL"})
@loopback.command('del')
@click.argument('loopback_name', metavar='<loopback_name>', required=True)
@click.pass_context
def del_loopback(ctx, loopback_name):
config_db = ctx.obj['db']
if is_loopback_name_valid(loopback_name) is False:
ctx.fail("{} is invalid, name should have prefix '{}' and suffix '{}' "
.format(loopback_name, CFG_LOOPBACK_PREFIX, CFG_LOOPBACK_NO))
lo_config_db = config_db.get_table('LOOPBACK_INTERFACE')
lo_intfs = [k for k, v in lo_config_db.items() if type(k) != tuple]
if loopback_name not in lo_intfs:
ctx.fail("{} does not exists".format(loopback_name))
ips = [ k[1] for k in lo_config_db if type(k) == tuple and k[0] == loopback_name ]
for ip in ips:
config_db.set_entry('LOOPBACK_INTERFACE', (loopback_name, ip), None)
config_db.set_entry('LOOPBACK_INTERFACE', loopback_name, None)
@config.group(cls=clicommon.AbbreviationGroup)
def ztp():
""" Configure Zero Touch Provisioning """
if os.path.isfile('/usr/bin/ztp') is False:
exit("ZTP feature unavailable in this image version")
if os.geteuid() != 0:
exit("Root privileges are required for this operation")
@ztp.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='ZTP will be restarted. You may lose switch data and connectivity, continue?')
@click.argument('run', required=False, type=click.Choice(["run"]))
def run(run):
"""Restart ZTP of the device."""
command = "ztp run -y"
clicommon.run_command(command, display_cmd=True)
@ztp.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Active ZTP session will be stopped and disabled, continue?')
@click.argument('disable', required=False, type=click.Choice(["disable"]))
def disable(disable):
"""Administratively Disable ZTP."""
command = "ztp disable -y"
clicommon.run_command(command, display_cmd=True)
@ztp.command()
@click.argument('enable', required=False, type=click.Choice(["enable"]))
def enable(enable):
"""Administratively Enable ZTP."""
command = "ztp enable"
clicommon.run_command(command, display_cmd=True)
#
# 'syslog' group ('config syslog ...')
#
@config.group(cls=clicommon.AbbreviationGroup, name='syslog')
@click.pass_context
def syslog_group(ctx):
"""Syslog server configuration tasks"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
@syslog_group.command('add')
@click.argument('syslog_ip_address', metavar='<syslog_ip_address>', required=True)
@click.pass_context
def add_syslog_server(ctx, syslog_ip_address):
""" Add syslog server IP """
if not clicommon.is_ipaddress(syslog_ip_address):
ctx.fail('Invalid ip address')
db = ctx.obj['db']
syslog_servers = db.get_table("SYSLOG_SERVER")
if syslog_ip_address in syslog_servers:
click.echo("Syslog server {} is already configured".format(syslog_ip_address))
return
else:
db.set_entry('SYSLOG_SERVER', syslog_ip_address, {'NULL': 'NULL'})
click.echo("Syslog server {} added to configuration".format(syslog_ip_address))
try:
click.echo("Restarting rsyslog-config service...")
clicommon.run_command("systemctl restart rsyslog-config", display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service rsyslog-config failed with error {}".format(e))
@syslog_group.command('del')
@click.argument('syslog_ip_address', metavar='<syslog_ip_address>', required=True)
@click.pass_context
def del_syslog_server(ctx, syslog_ip_address):
""" Delete syslog server IP """
if not clicommon.is_ipaddress(syslog_ip_address):
ctx.fail('Invalid IP address')
db = ctx.obj['db']
syslog_servers = db.get_table("SYSLOG_SERVER")
if syslog_ip_address in syslog_servers:
db.set_entry('SYSLOG_SERVER', '{}'.format(syslog_ip_address), None)
click.echo("Syslog server {} removed from configuration".format(syslog_ip_address))
else:
ctx.fail("Syslog server {} is not configured.".format(syslog_ip_address))
try:
click.echo("Restarting rsyslog-config service...")
clicommon.run_command("systemctl restart rsyslog-config", display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service rsyslog-config failed with error {}".format(e))
#
# 'ntp' group ('config ntp ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def ntp(ctx):
"""NTP server configuration tasks"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
@ntp.command('add')
@click.argument('ntp_ip_address', metavar='<ntp_ip_address>', required=True)
@click.pass_context
def add_ntp_server(ctx, ntp_ip_address):
""" Add NTP server IP """
if not clicommon.is_ipaddress(ntp_ip_address):
ctx.fail('Invalid ip address')
db = ctx.obj['db']
ntp_servers = db.get_table("NTP_SERVER")
if ntp_ip_address in ntp_servers:
click.echo("NTP server {} is already configured".format(ntp_ip_address))
return
else:
db.set_entry('NTP_SERVER', ntp_ip_address, {'NULL': 'NULL'})
click.echo("NTP server {} added to configuration".format(ntp_ip_address))
try:
click.echo("Restarting ntp-config service...")
clicommon.run_command("systemctl restart ntp-config", display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service ntp-config failed with error {}".format(e))
@ntp.command('del')
@click.argument('ntp_ip_address', metavar='<ntp_ip_address>', required=True)
@click.pass_context
def del_ntp_server(ctx, ntp_ip_address):
""" Delete NTP server IP """
if not clicommon.is_ipaddress(ntp_ip_address):
ctx.fail('Invalid IP address')
db = ctx.obj['db']
ntp_servers = db.get_table("NTP_SERVER")
if ntp_ip_address in ntp_servers:
db.set_entry('NTP_SERVER', '{}'.format(ntp_ip_address), None)
click.echo("NTP server {} removed from configuration".format(ntp_ip_address))
else:
ctx.fail("NTP server {} is not configured.".format(ntp_ip_address))
try:
click.echo("Restarting ntp-config service...")
clicommon.run_command("systemctl restart ntp-config", display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service ntp-config failed with error {}".format(e))
#
# 'sflow' group ('config sflow ...')
#
@config.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def sflow(ctx):
"""sFlow-related configuration tasks"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
#
# 'sflow' command ('config sflow enable')
#
@sflow.command()
@click.pass_context
def enable(ctx):
"""Enable sFlow"""
config_db = ctx.obj['db']
sflow_tbl = config_db.get_table('SFLOW')
if not sflow_tbl:
sflow_tbl = {'global': {'admin_state': 'up'}}
else:
sflow_tbl['global']['admin_state'] = 'up'
config_db.mod_entry('SFLOW', 'global', sflow_tbl['global'])
try:
proc = subprocess.Popen("systemctl is-active sflow", shell=True, text=True, stdout=subprocess.PIPE)
(out, err) = proc.communicate()
except SystemExit as e:
ctx.fail("Unable to check sflow status {}".format(e))
if out != "active":
log.log_info("sflow service is not enabled. Starting sflow docker...")
clicommon.run_command("sudo systemctl enable sflow")
clicommon.run_command("sudo systemctl start sflow")
#
# 'sflow' command ('config sflow disable')
#
@sflow.command()
@click.pass_context
def disable(ctx):
"""Disable sFlow"""
config_db = ctx.obj['db']
sflow_tbl = config_db.get_table('SFLOW')
if not sflow_tbl:
sflow_tbl = {'global': {'admin_state': 'down'}}
else:
sflow_tbl['global']['admin_state'] = 'down'
config_db.mod_entry('SFLOW', 'global', sflow_tbl['global'])
#
# 'sflow' command ('config sflow polling-interval ...')
#
@sflow.command('polling-interval')
@click.argument('interval', metavar='<polling_interval>', required=True,
type=int)
@click.pass_context
def polling_int(ctx, interval):
"""Set polling-interval for counter-sampling (0 to disable)"""
if interval not in range(5, 301) and interval != 0:
click.echo("Polling interval must be between 5-300 (0 to disable)")
config_db = ctx.obj['db']
sflow_tbl = config_db.get_table('SFLOW')
if not sflow_tbl:
sflow_tbl = {'global': {'admin_state': 'down'}}
sflow_tbl['global']['polling_interval'] = interval
config_db.mod_entry('SFLOW', 'global', sflow_tbl['global'])
def is_valid_sample_rate(rate):
return rate.isdigit() and int(rate) in range(256, 8388608 + 1)
#
# 'sflow interface' group
#
@sflow.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def interface(ctx):
"""Configure sFlow settings for an interface"""
pass
#
# 'sflow' command ('config sflow interface enable ...')
#
@interface.command()
@click.argument('ifname', metavar='<interface_name>', required=True, type=str)
@click.pass_context
def enable(ctx, ifname):
config_db = ctx.obj['db']
if not interface_name_is_valid(config_db, ifname) and ifname != 'all':
click.echo("Invalid interface name")
return
intf_dict = config_db.get_table('SFLOW_SESSION')
if intf_dict and ifname in intf_dict:
intf_dict[ifname]['admin_state'] = 'up'
config_db.mod_entry('SFLOW_SESSION', ifname, intf_dict[ifname])
else:
config_db.mod_entry('SFLOW_SESSION', ifname, {'admin_state': 'up'})
#
# 'sflow' command ('config sflow interface disable ...')
#
@interface.command()
@click.argument('ifname', metavar='<interface_name>', required=True, type=str)
@click.pass_context
def disable(ctx, ifname):
config_db = ctx.obj['db']
if not interface_name_is_valid(config_db, ifname) and ifname != 'all':
click.echo("Invalid interface name")
return
intf_dict = config_db.get_table('SFLOW_SESSION')
if intf_dict and ifname in intf_dict:
intf_dict[ifname]['admin_state'] = 'down'
config_db.mod_entry('SFLOW_SESSION', ifname, intf_dict[ifname])
else:
config_db.mod_entry('SFLOW_SESSION', ifname,
{'admin_state': 'down'})
#
# 'sflow' command ('config sflow interface sample-rate ...')
#
@interface.command('sample-rate')
@click.argument('ifname', metavar='<interface_name>', required=True, type=str)
@click.argument('rate', metavar='<sample_rate>', required=True, type=str)
@click.pass_context
def sample_rate(ctx, ifname, rate):
config_db = ctx.obj['db']
if not interface_name_is_valid(config_db, ifname) and ifname != 'all':
click.echo('Invalid interface name')
return
if not is_valid_sample_rate(rate) and rate != 'default':
click.echo('Error: Sample rate must be between 256 and 8388608 or default')
return
sess_dict = config_db.get_table('SFLOW_SESSION')
if sess_dict and ifname in sess_dict.keys():
if rate == 'default':
if 'sample_rate' not in sess_dict[ifname]:
return
del sess_dict[ifname]['sample_rate']
config_db.set_entry('SFLOW_SESSION', ifname, sess_dict[ifname])
return
sess_dict[ifname]['sample_rate'] = rate
config_db.mod_entry('SFLOW_SESSION', ifname, sess_dict[ifname])
else:
if rate != 'default':
config_db.mod_entry('SFLOW_SESSION', ifname, {'sample_rate': rate})
#
# 'sflow collector' group
#
@sflow.group(cls=clicommon.AbbreviationGroup)
@click.pass_context
def collector(ctx):
"""Add/Delete a sFlow collector"""
pass
def is_valid_collector_info(name, ip, port, vrf_name):
if len(name) > 16:
click.echo("Collector name must not exceed 16 characters")
return False
if port not in range(0, 65535 + 1):
click.echo("Collector port number must be between 0 and 65535")
return False
if not clicommon.is_ipaddress(ip):
click.echo("Invalid IP address")
return False
if vrf_name != 'default' and vrf_name != 'mgmt':
click.echo("Only 'default' and 'mgmt' VRF are supported")
return False
return True
#
# 'sflow' command ('config sflow collector add ...')
#
@collector.command()
@click.option('--port', required=False, type=int, default=6343,
help='Collector port number')
@click.option('--vrf', required=False, type=str, default='default',
help='Collector VRF')
@click.argument('name', metavar='<collector_name>', required=True)
@click.argument('ipaddr', metavar='<IPv4/v6_address>', required=True)
@click.pass_context
def add(ctx, name, ipaddr, port, vrf):
"""Add a sFlow collector"""
ipaddr = ipaddr.lower()
if not is_valid_collector_info(name, ipaddr, port, vrf):
return
config_db = ctx.obj['db']
collector_tbl = config_db.get_table('SFLOW_COLLECTOR')
if (collector_tbl and name not in collector_tbl and len(collector_tbl) == 2):
click.echo("Only 2 collectors can be configured, please delete one")
return
config_db.mod_entry('SFLOW_COLLECTOR', name,
{"collector_ip": ipaddr, "collector_port": port,
"collector_vrf": vrf})
return
#
# 'sflow' command ('config sflow collector del ...')
#
@collector.command('del')
@click.argument('name', metavar='<collector_name>', required=True)
@click.pass_context
def del_collector(ctx, name):
"""Delete a sFlow collector"""
config_db = ctx.obj['db']
collector_tbl = config_db.get_table('SFLOW_COLLECTOR')
if name not in collector_tbl:
click.echo("Collector: {} not configured".format(name))
return
config_db.mod_entry('SFLOW_COLLECTOR', name, None)
#
# 'sflow agent-id' group
#
@sflow.group(cls=clicommon.AbbreviationGroup, name='agent-id')
@click.pass_context
def agent_id(ctx):
"""Add/Delete a sFlow agent"""
pass
#
# 'sflow' command ('config sflow agent-id add ...')
#
@agent_id.command()
@click.argument('ifname', metavar='<interface_name>', required=True)
@click.pass_context
def add(ctx, ifname):
"""Add sFlow agent information"""
if ifname not in netifaces.interfaces():
click.echo("Invalid interface name")
return
config_db = ctx.obj['db']
sflow_tbl = config_db.get_table('SFLOW')
if not sflow_tbl:
sflow_tbl = {'global': {'admin_state': 'down'}}
if 'agent_id' in sflow_tbl['global']:
click.echo("Agent already configured. Please delete it first.")
return
sflow_tbl['global']['agent_id'] = ifname
config_db.mod_entry('SFLOW', 'global', sflow_tbl['global'])
#
# 'sflow' command ('config sflow agent-id del')
#
@agent_id.command('del')
@click.pass_context
def delete(ctx):
"""Delete sFlow agent information"""
config_db = ctx.obj['db']
sflow_tbl = config_db.get_table('SFLOW')
if not sflow_tbl:
sflow_tbl = {'global': {'admin_state': 'down'}}
if 'agent_id' not in sflow_tbl['global']:
click.echo("sFlow agent not configured.")
return
sflow_tbl['global'].pop('agent_id')
config_db.set_entry('SFLOW', 'global', sflow_tbl['global'])
#
# set ipv6 link local mode on a given interface
#
def set_ipv6_link_local_only_on_interface(config_db, interface_dict, interface_type, interface_name, mode):
curr_mode = config_db.get_entry(interface_type, interface_name).get('ipv6_use_link_local_only')
if curr_mode is not None:
if curr_mode == mode:
return
else:
if mode == "disable":
return
if mode == "enable":
config_db.mod_entry(interface_type, interface_name, {"ipv6_use_link_local_only": mode})
return
# If we are disabling the ipv6 link local on an interface, and if no other interface
# attributes/ip addresses are configured on the interface, delete the interface from the interface table
exists = False
for key in interface_dict.keys():
if not isinstance(key, tuple):
if interface_name == key:
#Interface bound to non-default-vrf do not delete the entry
if 'vrf_name' in interface_dict[key]:
if len(interface_dict[key]['vrf_name']) > 0:
exists = True
break
continue
if interface_name in key:
exists = True
break
if exists:
config_db.mod_entry(interface_type, interface_name, {"ipv6_use_link_local_only": mode})
else:
config_db.set_entry(interface_type, interface_name, None)
#
# 'ipv6' group ('config ipv6 ...')
#
@config.group()
@click.pass_context
def ipv6(ctx):
"""IPv6 configuration"""
#
# 'enable' command ('config ipv6 enable ...')
#
@ipv6.group()
@click.pass_context
def enable(ctx):
"""Enable IPv6 on all interfaces """
#
# 'link-local' command ('config ipv6 enable link-local')
#
@enable.command('link-local')
@click.pass_context
def enable_link_local(ctx):
"""Enable IPv6 link-local on all interfaces """
config_db = ConfigDBConnector()
config_db.connect()
vlan_member_table = config_db.get_table('VLAN_MEMBER')
portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')
mode = "enable"
# Enable ipv6 link local on VLANs
vlan_dict = config_db.get_table('VLAN')
for key in vlan_dict.keys():
set_ipv6_link_local_only_on_interface(config_db, vlan_dict, 'VLAN_INTERFACE', key, mode)
# Enable ipv6 link local on PortChannels
portchannel_dict = config_db.get_table('PORTCHANNEL')
for key in portchannel_dict.keys():
if interface_is_in_vlan(vlan_member_table, key):
continue
set_ipv6_link_local_only_on_interface(config_db, portchannel_dict, 'PORTCHANNEL_INTERFACE', key, mode)
port_dict = config_db.get_table('PORT')
for key in port_dict.keys():
if interface_is_in_portchannel(portchannel_member_table, key) or interface_is_in_vlan(vlan_member_table, key):
continue
set_ipv6_link_local_only_on_interface(config_db, port_dict, 'INTERFACE', key, mode)
#
# 'disable' command ('config ipv6 disable ...')
#
@ipv6.group()
@click.pass_context
def disable(ctx):
"""Disable IPv6 on all interfaces """
#
# 'link-local' command ('config ipv6 disable link-local')
#
@disable.command('link-local')
@click.pass_context
def disable_link_local(ctx):
"""Disable IPv6 link local on all interfaces """
config_db = ConfigDBConnector()
config_db.connect()
mode = "disable"
tables = ['INTERFACE', 'VLAN_INTERFACE', 'PORTCHANNEL_INTERFACE']
for table_type in tables:
table_dict = config_db.get_table(table_type)
if table_dict:
for key in table_dict.keys():
if isinstance(key, str) is False:
continue
set_ipv6_link_local_only_on_interface(config_db, table_dict, table_type, key, mode)
#
# 'rate' group ('config rate ...')
#
@config.group()
def rate():
"""Set port rates configuration."""
pass
@rate.command()
@click.argument('interval', metavar='<interval>', type=click.IntRange(min=1, max=1000), required=True)
@click.argument('rates_type', type=click.Choice(['all', 'port', 'rif', 'flowcnt-trap']), default='all')
def smoothing_interval(interval, rates_type):
"""Set rates smoothing interval """
counters_db = swsssdk.SonicV2Connector()
counters_db.connect('COUNTERS_DB')
alpha = 2.0/(interval + 1)
if rates_type in ['port', 'all']:
counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_SMOOTH_INTERVAL', interval)
counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_ALPHA', alpha)
if rates_type in ['rif', 'all']:
counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_SMOOTH_INTERVAL', interval)
counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_ALPHA', alpha)
if rates_type in ['flowcnt-trap', 'all']:
counters_db.set('COUNTERS_DB', 'RATES:TRAP', 'TRAP_SMOOTH_INTERVAL', interval)
counters_db.set('COUNTERS_DB', 'RATES:TRAP', 'TRAP_ALPHA', alpha)
# Load plugins and register them
helper = util_base.UtilHelper()
helper.load_and_register_plugins(plugins, config)
#
# 'subinterface' group ('config subinterface ...')
#
@config.group()
@click.pass_context
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
def subinterface(ctx, redis_unix_socket_path):
"""subinterface-related configuration tasks"""
kwargs = {}
if redis_unix_socket_path:
kwargs['unix_socket_path'] = redis_unix_socket_path
config_db = ConfigDBConnector(**kwargs)
config_db.connect(wait_for_init=False)
ctx.obj = {'db': config_db}
def subintf_vlan_check(config_db, parent_intf, vlan):
subintf_db = config_db.get_table('VLAN_SUB_INTERFACE')
subintf_names = [k for k in subintf_db if type(k) != tuple]
for subintf in subintf_names:
sub_intf_sep_idx = subintf.find(VLAN_SUB_INTERFACE_SEPARATOR)
if sub_intf_sep_idx == -1:
continue
if parent_intf == subintf[:sub_intf_sep_idx]:
if 'vlan' in subintf_db[subintf]:
if str(vlan) == subintf_db[subintf]['vlan']:
return True
else:
vlan_id = subintf[sub_intf_sep_idx + 1:]
if str(vlan) == vlan_id:
return True
return False
@subinterface.command('add')
@click.argument('subinterface_name', metavar='<subinterface_name>', required=True)
@click.argument('vid', metavar='<vid>', required=False, type=click.IntRange(1,4094))
@click.pass_context
def add_subinterface(ctx, subinterface_name, vid):
sub_intf_sep_idx = subinterface_name.find(VLAN_SUB_INTERFACE_SEPARATOR)
if sub_intf_sep_idx == -1:
ctx.fail("{} is invalid vlan subinterface".format(subinterface_name))
interface_alias = subinterface_name[:sub_intf_sep_idx]
if interface_alias is None:
ctx.fail("{} invalid subinterface".format(interface_alias))
if interface_alias.startswith("Po") is True:
intf_table_name = CFG_PORTCHANNEL_PREFIX
elif interface_alias.startswith("Eth") is True:
intf_table_name = 'PORT'
config_db = ctx.obj['db']
port_dict = config_db.get_table(intf_table_name)
if interface_alias is not None:
if not port_dict:
ctx.fail("{} parent interface not found. {} table none".format(interface_alias, intf_table_name))
if get_intf_longname(interface_alias) not in port_dict.keys():
ctx.fail("{} parent interface not found".format(subinterface_name))
# Validate if parent is portchannel member
portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')
if interface_is_in_portchannel(portchannel_member_table, interface_alias):
ctx.fail("{} is configured as a member of portchannel. Cannot configure subinterface"
.format(interface_alias))
# Validate if parent is vlan member
vlan_member_table = config_db.get_table('VLAN_MEMBER')
if interface_is_in_vlan(vlan_member_table, interface_alias):
ctx.fail("{} is configured as a member of vlan. Cannot configure subinterface"
.format(interface_alias))
sub_intfs = [k for k,v in config_db.get_table('VLAN_SUB_INTERFACE').items() if type(k) != tuple]
if subinterface_name in sub_intfs:
ctx.fail("{} already exists".format(subinterface_name))
subintf_dict = {}
if vid is not None:
subintf_dict.update({"vlan" : vid})
if subintf_vlan_check(config_db, get_intf_longname(interface_alias), vid) is True:
ctx.fail("Vlan {} encap already configured on other subinterface on {}".format(vid, interface_alias))
subintf_dict.update({"admin_status" : "up"})
config_db.set_entry('VLAN_SUB_INTERFACE', subinterface_name, subintf_dict)
@subinterface.command('del')
@click.argument('subinterface_name', metavar='<subinterface_name>', required=True)
@click.pass_context
def del_subinterface(ctx, subinterface_name):
sub_intf_sep_idx = subinterface_name.find(VLAN_SUB_INTERFACE_SEPARATOR)
if sub_intf_sep_idx == -1:
ctx.fail("{} is invalid vlan subinterface".format(subinterface_name))
config_db = ctx.obj['db']
#subinterface_name = subintf_get_shortname(subinterface_name)
if interface_name_is_valid(config_db, subinterface_name) is False:
ctx.fail("{} is invalid ".format(subinterface_name))
subintf_config_db = config_db.get_table('VLAN_SUB_INTERFACE')
sub_intfs = [k for k,v in subintf_config_db.items() if type(k) != tuple]
if subinterface_name not in sub_intfs:
ctx.fail("{} does not exists".format(subinterface_name))
ips = {}
ips = [ k[1] for k in config_db.get_table('VLAN_SUB_INTERFACE') if type(k) == tuple and k[0] == subinterface_name ]
for ip in ips:
try:
ipaddress.ip_network(ip, strict=False)
config_db.set_entry('VLAN_SUB_INTERFACE', (subinterface_name, ip), None)
except ValueError:
ctx.fail("Invalid ip {} found on interface {}".format(ip, subinterface_name))
subintf_config_db = config_db.get_table('INTERFACE')
ips = [ k[1] for k in subintf_config_db if type(k) == tuple and k[0] == subinterface_name ]
for ip in ips:
config_db.set_entry('INTERFACE', (subinterface_name, ip), None)
config_db.set_entry('VLAN_SUB_INTERFACE', subinterface_name, None)
if __name__ == '__main__':
config()
|
<reponame>NickHerrig/bronzebeard<gh_stars>0
import argparse
from collections import namedtuple
from ctypes import c_uint32
from functools import partial
import re
import struct
import sys
REGISTERS = {
'x0': 0, 'zero': 0,
'x1': 1, 'ra': 1,
'x2': 2, 'sp': 2,
'x3': 3, 'gp': 3,
'x4': 4, 'tp': 4,
'x5': 5, 't0': 5,
'x6': 6, 't1': 6,
'x7': 7, 't2': 7,
'x8': 8, 's0': 8, 'fp': 8,
'x9': 9, 's1': 9,
'x10': 10, 'a0': 10,
'x11': 11, 'a1': 11,
'x12': 12, 'a2': 12,
'x13': 13, 'a3': 13,
'x14': 14, 'a4': 14,
'x15': 15, 'a5': 15,
'x16': 16, 'a6': 16,
'x17': 17, 'a7': 17,
'x18': 18, 's2': 18,
'x19': 19, 's3': 19,
'x20': 20, 's4': 20,
'x21': 21, 's5': 21,
'x22': 22, 's6': 22,
'x23': 23, 's7': 23,
'x24': 24, 's8': 24,
'x25': 25, 's9': 25,
'x26': 26, 's10': 26,
'x27': 27, 's11': 27,
'x28': 28, 't3': 28,
'x29': 29, 't4': 29,
'x30': 30, 't5': 30,
'x31': 31, 't6': 31,
}
def lookup_register(reg):
# check if register corresponds to a valid name
if reg in REGISTERS:
reg = REGISTERS[reg]
# ensure register is a number
try:
reg = int(reg)
except ValueError:
raise ValueError('Register is not a number or valid name: {}'.format(reg))
# ensure register is between 0 and 31
if reg < 0 or reg > 31:
raise ValueError('Register must be between 0 and 31: {}'.format(reg))
return reg
def r_type(rd, rs1, rs2, opcode, funct3, funct7):
rd = lookup_register(rd)
rs1 = lookup_register(rs1)
rs2 = lookup_register(rs2)
code = 0
code |= opcode
code |= rd << 7
code |= funct3 << 12
code |= rs1 << 15
code |= rs2 << 20
code |= funct7 << 25
return struct.pack('<I', code)
def i_type(rd, rs1, imm, opcode, funct3):
rd = lookup_register(rd)
rs1 = lookup_register(rs1)
if imm < -0x800 or imm > 0x7ff:
raise ValueError('12-bit immediate must be between -0x800 (-2048) and 0x7ff (2047): {}'.format(imm))
imm = c_uint32(imm).value & 0b111111111111
code = 0
code |= opcode
code |= rd << 7
code |= funct3 << 12
code |= rs1 << 15
code |= imm << 20
return struct.pack('<I', code)
def s_type(rs1, rs2, imm, opcode, funct3):
rs1 = lookup_register(rs1)
rs2 = lookup_register(rs2)
if imm < -0x800 or imm > 0x7ff:
raise ValueError('12-bit immediate must be between -0x800 (-2048) and 0x7ff (2047): {}'.format(imm))
imm = c_uint32(imm).value & 0b111111111111
imm_11_5 = (imm >> 5) & 0b1111111
imm_4_0 = imm & 0b11111
code = 0
code |= opcode
code |= imm_4_0 << 7
code |= funct3 << 12
code |= rs1 << 15
code |= rs2 << 20
code |= imm_11_5 << 25
return struct.pack('<I', code)
def b_type(rs1, rs2, imm, opcode, funct3):
rs1 = lookup_register(rs1)
rs2 = lookup_register(rs2)
if imm < -0x1000 or imm > 0x0fff:
raise ValueError('12-bit multiple of 2 immediate must be between -0x1000 (-4096) and 0x0fff (4095): {}'.format(imm))
if imm % 2 == 1:
raise ValueError('12-bit multiple of 2 immediate must be a muliple of 2: {}'.format(imm))
imm = imm // 2
imm = c_uint32(imm).value & 0b111111111111
imm_12 = (imm >> 11) & 0b1
imm_11 = (imm >> 10) & 0b1
imm_10_5 = (imm >> 4) & 0b111111
imm_4_1 = imm & 0b1111
code = 0
code |= opcode
code |= imm_11 << 7
code |= imm_4_1 << 8
code |= funct3 << 12
code |= rs1 << 15
code |= rs2 << 20
code |= imm_10_5 << 25
code |= imm_12 << 31
return struct.pack('<I', code)
def u_type(rd, imm, opcode):
rd = lookup_register(rd)
if imm < -0x80000 or imm > 0x7ffff:
raise ValueError('20-bit immediate must be between -0x80000 (-524288) and 0x7ffff (524287): {}'.format(imm))
imm = c_uint32(imm).value & 0b11111111111111111111
code = 0
code |= opcode
code |= rd << 7
code |= imm << 12
return struct.pack('<I', code)
def j_type(rd, imm, opcode):
rd = lookup_register(rd)
if imm < -0x100000 or imm > 0x0fffff:
raise ValueError('20-bit multiple of 2 immediate must be between -0x100000 (-1048576) and 0x0fffff (1048575): {}'.format(imm))
if imm % 2 == 1:
raise ValueError('20-bit multiple of 2 immediate must be a muliple of 2: {}'.format(imm))
imm = imm // 2
imm = c_uint32(imm).value & 0b11111111111111111111
imm_20 = (imm >> 19) & 0b1
imm_19_12 = (imm >> 11) & 0b11111111
imm_11 = (imm >> 10) & 0b1
imm_10_1 = imm & 0b1111111111
code = 0
code |= opcode
code |= rd << 7
code |= imm_19_12 << 12
code |= imm_11 << 20
code |= imm_10_1 << 21
code |= imm_20 << 31
return struct.pack('<I', code)
LUI = partial(u_type, opcode=0b0110111)
AUIPC = partial(u_type, opcode=0b0010111)
JAL = partial(j_type, opcode=0b1101111)
JALR = partial(i_type, opcode=0b1100111, funct3=0b000)
BEQ = partial(b_type, opcode=0b1100011, funct3=0b000)
BNE = partial(b_type, opcode=0b1100011, funct3=0b001)
BLT = partial(b_type, opcode=0b1100011, funct3=0b100)
BGE = partial(b_type, opcode=0b1100011, funct3=0b101)
BLTU = partial(b_type, opcode=0b1100011, funct3=0b110)
BGEU = partial(b_type, opcode=0b1100011, funct3=0b111)
LB = partial(i_type, opcode=0b0000011, funct3=0b000)
LH = partial(i_type, opcode=0b0000011, funct3=0b001)
LW = partial(i_type, opcode=0b0000011, funct3=0b010)
LBU = partial(i_type, opcode=0b0000011, funct3=0b100)
LHU = partial(i_type, opcode=0b0000011, funct3=0b101)
SB = partial(s_type, opcode=0b0100011, funct3=0b000)
SH = partial(s_type, opcode=0b0100011, funct3=0b001)
SW = partial(s_type, opcode=0b0100011, funct3=0b010)
ADDI = partial(i_type, opcode=0b0010011, funct3=0b000)
SLTI = partial(i_type, opcode=0b0010011, funct3=0b010)
SLTIU = partial(i_type, opcode=0b0010011, funct3=0b011)
XORI = partial(i_type, opcode=0b0010011, funct3=0b100)
ORI = partial(i_type, opcode=0b0010011, funct3=0b110)
ANDI = partial(i_type, opcode=0b0010011, funct3=0b111)
SLLI = partial(r_type, opcode=0b0010011, funct3=0b001, funct7=0b0000000)
SRLI = partial(r_type, opcode=0b0010011, funct3=0b101, funct7=0b0000000)
SRAI = partial(r_type, opcode=0b0010011, funct3=0b101, funct7=0b0100000)
ADD = partial(r_type, opcode=0b0110011, funct3=0b000, funct7=0b0000000)
SUB = partial(r_type, opcode=0b0110011, funct3=0b000, funct7=0b0100000)
SLL = partial(r_type, opcode=0b0110011, funct3=0b001, funct7=0b0000000)
SLT = partial(r_type, opcode=0b0110011, funct3=0b010, funct7=0b0000000)
SLTU = partial(r_type, opcode=0b0110011, funct3=0b011, funct7=0b0000000)
XOR = partial(r_type, opcode=0b0110011, funct3=0b100, funct7=0b0000000)
SRL = partial(r_type, opcode=0b0110011, funct3=0b101, funct7=0b0000000)
SRA = partial(r_type, opcode=0b0110011, funct3=0b101, funct7=0b0100000)
OR = partial(r_type, opcode=0b0110011, funct3=0b110, funct7=0b0000000)
AND = partial(r_type, opcode=0b0110011, funct3=0b111, funct7=0b0000000)
R_TYPE_INSTRUCTIONS = {
'slli': SLLI,
'srli': SRLI,
'srai': SRAI,
'add': ADD,
'sub': SUB,
'sll': SLL,
'slt': SLT,
'sltu': SLTU,
'xor': XOR,
'srl': SRL,
'sra': SRA,
'or': OR,
'and': AND,
}
I_TYPE_INSTRUCTIONS = {
'jalr': JALR,
'lb': LB,
'lh': LH,
'lw': LW,
'lbu': LBU,
'lhu': LHU,
'addi': ADDI,
'slti': SLTI,
'sltiu': SLTIU,
'xori': XORI,
'ori': ORI,
'andi': ANDI,
}
S_TYPE_INSTRUCTIONS = {
'sb': SB,
'sh': SH,
'sw': SW,
}
B_TYPE_INSTRUCTIONS = {
'beq': BEQ,
'bne': BNE,
'blt': BLT,
'bge': BGE,
'bltu': BLTU,
'bgeu': BGEU,
}
U_TYPE_INSTRUCTIONS = {
'lui': LUI,
'auipc': AUIPC,
}
J_TYPE_INSTRUCTIONS = {
'jal': JAL,
}
INSTRUCTIONS = {}
INSTRUCTIONS.update(R_TYPE_INSTRUCTIONS)
INSTRUCTIONS.update(I_TYPE_INSTRUCTIONS)
INSTRUCTIONS.update(S_TYPE_INSTRUCTIONS)
INSTRUCTIONS.update(B_TYPE_INSTRUCTIONS)
INSTRUCTIONS.update(U_TYPE_INSTRUCTIONS)
INSTRUCTIONS.update(J_TYPE_INSTRUCTIONS)
# Arg types:
# name: str
# label: str
# alignment: int
# fmt: str
# data: bytes
# rd, rs1, rs2: int, str
# expr: %position, %offset, %hi, %lo, or simple python expression
# items
Align = namedtuple('Align', 'alignment') # 0-3 bytes
Label = namedtuple('Label', 'name') # 0 bytes
Constant = namedtuple('Constant', 'name expr') # 0 bytes
Pack = namedtuple('Pack', 'fmt expr') # struct.calcsize(fmt) bytes
Blob = namedtuple('Blob', 'data') # len(data) bytes
RTypeInstruction = namedtuple('RTypeInstruction', 'name rd rs1 rs2') # 4 bytes
ITypeInstruction = namedtuple('ITypeInstruction', 'name rd rs1 expr') # 4 bytes
STypeInstruction = namedtuple('STypeInstruction', 'name rs1 rs2 expr') # 4 bytes
BTypeInstruction = namedtuple('BTypeInstruction', 'name rs1 rs2 expr') # 4 bytes
UTypeInstruction = namedtuple('UTypeInstruction', 'name rd expr') # 4 bytes
JTypeInstruction = namedtuple('JTypeInstruction', 'name rd expr') # 4 bytes
# expression modifiers
Position = namedtuple('Position', 'label expr')
Offset = namedtuple('Offset', 'label')
Hi = namedtuple('Hi', 'expr')
Lo = namedtuple('Lo', 'expr')
def sign_extend(value, bits):
sign_bit = 1 << (bits - 1)
return (value & (sign_bit - 1)) - (value & sign_bit)
def relocate_hi(imm):
if imm & 0x800:
imm += 2**12
return sign_extend((imm >> 12) & 0x000fffff, 20)
def relocate_lo(imm):
return sign_extend(imm & 0x00000fff, 12)
def lex_assembly(assembly):
assembly = re.sub(r'#.*?$', r'', assembly, flags=re.MULTILINE) # strip comments
lines = assembly.splitlines() # split into lines
lines = [line.strip() for line in lines] # strip whitespace
lines = [line for line in lines if len(line) > 0] # skip empty lines
items = [re.split(r'[\s,()\'"]+', line) for line in lines] # split lines into tokens
# remove empty tokens
for item in items:
while '' in item:
item.remove('')
return items
def parse_assembly(items):
def parse_expression(expr):
if expr[0].lower() == '%position':
_, label, *expr = expr
expr = ' '.join(expr)
return Position(label, expr)
elif expr[0].lower() == '%offset':
_, label = expr
return Offset(label)
elif expr[0].lower() == '%hi':
_, *expr = expr
expr = parse_expression(expr)
return Hi(expr)
elif expr[0].lower() == '%lo':
_, *expr = expr
expr = parse_expression(expr)
return Lo(expr)
else:
return ' '.join(expr)
program = []
for item in items:
# labels
if len(item) == 1 and item[0].endswith(':'):
label = item[0]
label = label.rstrip(':')
item = Label(label)
program.append(item)
# constants
elif len(item) >= 3 and item[1] == '=':
name, _, *expr = item
expr = parse_expression(expr)
item = Constant(name, expr)
program.append(item)
# aligns
elif item[0].lower() == 'align':
_, alignment = item
alignment = int(alignment)
item = Align(alignment)
program.append(item)
# packs
elif item[0].lower() == 'pack':
_, fmt, *expr = item
expr = parse_expression(expr)
item = Pack(fmt, expr)
program.append(item)
# bytes
elif item[0].lower() == 'bytes':
_, *data = item
data = [int(byte, base=0) for byte in data]
for byte in data:
if byte < 0 or byte > 255:
raise SystemExit('bytes literal not in range [0, 255]: {}'.format(data))
data = bytes(data)
item = Blob(data)
program.append(item)
# string
elif item[0].lower() == 'string':
_, *data = item
data = ' '.join(data)
data = data.encode()
item = Blob(data)
program.append(item)
# r-type instructions
elif item[0].lower() in R_TYPE_INSTRUCTIONS:
name, rd, rs1, rs2 = item
name = name.lower()
item = RTypeInstruction(name, rd, rs1, rs2)
program.append(item)
# i-type instructions
elif item[0].lower() in I_TYPE_INSTRUCTIONS:
name, rd, rs1, *expr = item
name = name.lower()
expr = parse_expression(expr)
item = ITypeInstruction(name, rd, rs1, expr)
program.append(item)
# s-type instructions
elif item[0].lower() in S_TYPE_INSTRUCTIONS:
name, rs1, rs2, *expr = item
name = name.lower()
expr = parse_expression(expr)
item = STypeInstruction(name, rs1, rs2, expr)
program.append(item)
# b-type instructions
elif item[0].lower() in B_TYPE_INSTRUCTIONS:
name, rs1, rs2, *expr = item
name = name.lower()
# ensure behavior is "offset" for branch instructions
if expr[0] != '%offset':
expr.insert(0, '%offset')
expr = parse_expression(expr)
item = BTypeInstruction(name, rs1, rs2, expr)
program.append(item)
# u-type instructions
elif item[0].lower() in U_TYPE_INSTRUCTIONS:
name, rd, *expr = item
name = name.lower()
expr = parse_expression(expr)
item = UTypeInstruction(name, rd, expr)
program.append(item)
# j-type instructions
elif item[0].lower() in J_TYPE_INSTRUCTIONS:
name, rd, *expr = item
name = name.lower()
# ensure behavior is "offset" for jump instructions
if expr[0] != '%offset':
expr.insert(0, '%offset')
expr = parse_expression(expr)
item = JTypeInstruction(name, rd, expr)
program.append(item)
else:
raise SystemExit('invalid item: {}'.format(' '.join(item)))
return program
# helper func, not a pass
def resolve_expression(expr, env, position):
# TODO: better error messages
try:
if type(expr) == Position:
dest = env[expr.label]
base = eval(expr.expr, env)
return base + dest
elif type(expr) == Offset:
dest = env[expr.label]
return dest - position
elif type(expr) == Hi:
if type(expr.expr) in [Position, Offset]:
value = resolve_expression(expr.expr, env, position)
else:
value = eval(expr.expr, env)
value = relocate_hi(value)
return value
elif type(expr) == Lo:
if type(expr.expr) in [Position, Offset]:
value = resolve_expression(expr.expr, env, position)
else:
value = eval(expr.expr, env)
value = relocate_lo(value)
return value
else:
value = eval(expr, env)
return value
except:
raise SystemExit('invalid expression: {}'.format(expr))
def resolve_aligns(program):
position = 0
output = []
for item in program:
if type(item) == Align:
padding = item.alignment - (position % item.alignment)
if padding == item.alignment:
continue
position += padding
output.append(Blob(b'\x00' * padding))
elif type(item) == Label:
output.append(item)
elif type(item) == Constant:
output.append(item)
elif type(item) == Pack:
position += struct.calcsize(item.fmt)
output.append(item)
elif type(item) == Blob:
position += len(item.data)
output.append(item)
else: # instruction
position += 4
output.append(item)
return output
def resolve_labels(program, env):
env = dict(env)
position = 0
output = []
for item in program:
if type(item) == Label:
env[item.name] = position
elif type(item) == Constant:
output.append(item)
elif type(item) == Pack:
position += struct.calcsize(item.fmt)
output.append(item)
elif type(item) == Blob:
position += len(item.data)
output.append(item)
else: # instruction
position += 4
output.append(item)
return output, env
def resolve_constants(program, env):
env = dict(env)
position = 0
output = []
for item in program:
if type(item) == Constant:
if item.name in REGISTERS:
raise SystemExit('constant name shadows register name: {}'.format(item.name))
env[item.name] = resolve_expression(item.expr, env, position)
elif type(item) == Pack:
position += struct.calcsize(item.fmt)
output.append(item)
elif type(item) == Blob:
position += len(item.data)
output.append(item)
else: # instruction
position += 4
output.append(item)
return output, env
def resolve_registers(program, env):
output = []
for item in program:
if type(item) == RTypeInstruction:
name, rd, rs1, rs2 = item
rd = env.get(rd) or rd
rs1 = env.get(rs1) or rs1
rs2 = env.get(rs2) or rs2
inst = RTypeInstruction(name, rd, rs1, rs2)
output.append(inst)
elif type(item) == ITypeInstruction:
name, rd, rs1, expr = item
rd = env.get(rd) or rd
rs1 = env.get(rs1) or rs1
inst = ITypeInstruction(name, rd, rs1, expr)
output.append(inst)
elif type(item) == STypeInstruction:
name, rs1, rs2, expr = item
rs1 = env.get(rs1) or rs1
rs2 = env.get(rs2) or rs2
inst = STypeInstruction(name, rs1, rs2, expr)
output.append(inst)
elif type(item) == BTypeInstruction:
name, rs1, rs2, expr = item
rs1 = env.get(rs1) or rs1
rs2 = env.get(rs2) or rs2
inst = BTypeInstruction(name, rs1, rs2, expr)
output.append(inst)
elif type(item) == UTypeInstruction:
name, rd, expr = item
rd = env.get(rd) or rd
inst = UTypeInstruction(name, rd, expr)
output.append(inst)
elif type(item) == JTypeInstruction:
name, rd, expr = item
rd = env.get(rd) or rd
inst = JTypeInstruction(name, rd, expr)
output.append(inst)
else:
output.append(item)
return output
def resolve_immediates(program, env):
position = 0
# check for items that have an immediate field and resolve it
output = []
for item in program:
if type(item) == ITypeInstruction:
name, rd, rs1, expr = item
imm = resolve_expression(expr, env, position)
inst = ITypeInstruction(name, rd, rs1, imm)
position += 4
output.append(inst)
elif type(item) == STypeInstruction:
name, rs1, rs2, expr = item
imm = resolve_expression(expr, env, position)
inst = STypeInstruction(name, rs1, rs2, imm)
position += 4
output.append(inst)
elif type(item) == BTypeInstruction:
name, rs1, rs2, expr = item
imm = resolve_expression(expr, env, position)
inst = BTypeInstruction(name, rs1, rs2, imm)
position += 4
output.append(inst)
elif type(item) == UTypeInstruction:
name, rd, expr = item
imm = resolve_expression(expr, env, position)
inst = UTypeInstruction(name, rd, imm)
position += 4
output.append(inst)
elif type(item) == JTypeInstruction:
name, rd, expr = item
imm = resolve_expression(expr, env, position)
inst = JTypeInstruction(name, rd, imm)
position += 4
output.append(inst)
elif type(item) == Pack:
fmt, expr = item
imm = resolve_expression(expr, env, position)
pack = Pack(fmt, imm)
position += struct.calcsize(fmt)
output.append(pack)
elif type(item) == Blob:
position += len(item.data)
output.append(item)
else:
position += 4
output.append(item)
return output
def resolve_instructions(program):
output = []
for item in program:
if type(item) == RTypeInstruction:
name, rd, rs1, rs2 = item
encode_func = INSTRUCTIONS[name]
code = encode_func(rd, rs1, rs2)
blob = Blob(code)
output.append(blob)
elif type(item) == ITypeInstruction:
name, rd, rs1, imm = item
encode_func = INSTRUCTIONS[name]
code = encode_func(rd, rs1, imm)
blob = Blob(code)
output.append(blob)
elif type(item) == STypeInstruction:
name, rs1, rs2, imm = item
encode_func = INSTRUCTIONS[name]
code = encode_func(rs1, rs2, imm)
blob = Blob(code)
output.append(blob)
elif type(item) == BTypeInstruction:
name, rs1, rs2, imm = item
encode_func = INSTRUCTIONS[name]
code = encode_func(rs1, rs2, imm)
blob = Blob(code)
output.append(blob)
elif type(item) == UTypeInstruction:
name, rd, imm = item
encode_func = INSTRUCTIONS[name]
code = encode_func(rd, imm)
blob = Blob(code)
output.append(blob)
elif type(item) == JTypeInstruction:
name, rd, imm = item
encode_func = INSTRUCTIONS[name]
code = encode_func(rd, imm)
blob = Blob(code)
output.append(blob)
else:
output.append(item)
return output
def resolve_packs(program):
output = []
for item in program:
if type(item) == Pack:
fmt, imm = item
data = struct.pack(fmt, imm)
blob = Blob(data)
output.append(blob)
else:
output.append(item)
return output
def resolve_blobs(program):
output = bytearray()
for item in program:
if type(item) != Blob:
raise SystemExit('expected only blobs but got: {}'.format(item))
output.extend(item.data)
return output
# Passes:
# 0. Lex + Parse source
# 1. Resolve aligns (convert aligns to blobs based on position)
# 2. Resolve labels (store label locations into env)
# 3. Resolve constants (eval expr and update env)
# 4. Resolve registers (could be constants for readability)
# 5. Resolve immediates (Position, Offset, Hi, Lo)
# 6. Resolve instructions (convert xTypeInstruction to Blob)
# 7. Resolve packs (convert Pack to Blob)
# 8. Resolve blobs (merge all Blobs into a single binary)
def assemble(source):
"""
Assemble a RISC-V assembly program into a raw binary.
:param source: A string of the assembly source program.
:returns: The assembled binary as bytes.
"""
items = lex_assembly(source)
prog = parse_assembly(items)
# exclude Python builtins from eval env
# https://docs.python.org/3/library/functions.html#eval
env = {
'__builtins__': None,
}
env.update(REGISTERS)
prog = resolve_aligns(prog)
prog, env = resolve_labels(prog, env)
prog, env = resolve_constants(prog, env)
prog = resolve_registers(prog, env)
prog = resolve_immediates(prog, env)
prog = resolve_instructions(prog)
prog = resolve_packs(prog)
prog = resolve_blobs(prog)
return prog
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Assemble RISC-V source code',
prog='python -m bronzebeard.asm',
)
parser.add_argument('input_asm', help='input source file')
parser.add_argument('output_bin', help='output binary file')
args = parser.parse_args()
with open(args.input_asm) as f:
source = f.read()
binary = assemble(source)
with open(args.output_bin, 'wb') as f:
f.write(binary)
|
<reponame>cuauv/software<gh_stars>10-100
from mission.framework.primitive import (
Zero,
Log,
AlwaysLog,
Succeed,
Fail,
FunctionTask,
NoOp
)
from mission.framework.combinators import (
Sequential,
Concurrent,
MasterConcurrent,
Retry,
Conditional,
While
)
from mission.framework.targeting import ForwardTarget, PIDLoop, HeadingTarget
from mission.framework.task import Task
from mission.framework.movement import VelocityY, VelocityX, RelativeToInitialHeading, Heading
from mission.framework.position import MoveX
from mission.framework.search import SearchFor, SwaySearch, VelocitySwaySearch, MoveX
from mission.missions.will_common import Consistent
from mission.missions.attilus_garbage import PIDStride, PIDSway, SwayOnlySearch, SlowHeading
from mission.missions.poly import polygon
from mission.framework.timing import Timer, Timed, Timeout
import shm
CAM_CENTER = (shm.vamp_buoy_results.camera_x.get(), shm.vamp_buoy_results.camera_y.get())
TRIANGLE = ("vetalas", "draugr", "aswang")
single = "jiangshi"
CALL = "draugr"
SIZE_THRESH = 8000
DIRECTION = 1 # -1 if left
BUOY_DEPTH = 2
last_visible = None
def call_buoy_center():
return (getattr(shm.vamp_buoy_results, "%s_center_x"%CALL).get(), getattr(shm.vamp_buoy_results, "%s_center_y"%CALL).get())
def any_buoy_center():
b = which_buoy_visible()
return (getattr(shm.vamp_buoy_results, "%s_center_x"%b).get(), getattr(shm.vamp_buoy_results, "%s_center_y"%b).get())
def single_buoy_center():
return (getattr(shm.vamp_buoy_results, "%s_center_x"%single).get(), getattr(shm.vamp_buoy_results, "%s_center_y"%single).get())
def _which_buoy_visible():
for b in TRIANGLE:
if getattr(shm.vamp_buoy_results, "%s_visible"%b).get():
last_visible = b
return b
def which_buoy_visible():
global last_visible
b = _which_buoy_visible()
if b is not None: last_visible=b
return last_visible
def call_buoy_visible():
return _which_buoy_visible() == CALL
def single_buoy_visible():
return getattr(shm.vamp_buoy_results, "%s_visible"%single).get()
def call_buoy_size():
return getattr(shm.vamp_buoy_results, "%s_size"%CALL).get()
def single_buoy_size():
return getattr(shm.vamp_buoy_results, "%s_size"%single).get()
def any_buoy_size():
b = which_buoy_visible()
return getattr(shm.vamp_buoy_results, "%s_size"%b).get()
def align_call_h():
return getattr(shm.vamp_buoy_results, "%s_align_h"%CALL).get()
def align_single_h():
return getattr(shm.vamp_buoy_results, "%s_align_h"%single).get()
def align_any_h():
b = which_buoy_visible()
return getattr(shm.vamp_buoy_results, "%s_align_h"%b).get()
def triangle_visible():
for b in TRIANGLE:
if getattr(shm.vamp_buoy_results, "%s_visible"%b).get():
return True
return False
last_seen = "draugr"
def set_last_seen():
global last_seen
last_seen = which_buoy_visible()
return True
def get_sway_direction():
global last_seen
return not (getattr(shm.vamp_buoy_results, "%s_center_x"%last_seen).get() < CAM_CENTER[0])
# Search for buoy using SwayOnlySearch
TinySearch = lambda backspeed=0.2, backtime=3: Sequential(
Zero(),
Log('Doing TinySearch to see if we can find called'),
Timeout(SearchFor(
SwayOnlySearch(right_first=get_sway_direction()),
call_buoy_visible,
consistent_frames=(0.5*60, 1.0*60)
), 20),
FunctionTask(set_last_seen),
Zero(),
)
# Back up, find the triangle buoy again and use it to find the called side
ReSearch = lambda: Sequential(
SearchTriangleOnFail(),
AlignAnyNormal(),
SearchCalled())
# Decorator that wraps a task to search for the called side of the buoy if it fails
withReSearchCalledOnFail = lambda task: lambda: Retry(lambda: \
Conditional(main_task=task(), on_fail= \
Fail(TinySearch())), attempts=2)
# The final fallback case. If the called side cannot be found, attempt to ram any side of the triangular buoy if possible.
RamAnything = lambda backspeed=0.2, backtime=10: Sequential(
Log('Failed, backing up'),
Zero(),
Timeout(SearchTriangle(), 200),
AlignAnyNormal(),
ApproachAny(),
RamV())
# Decorator that wraps a task to Ram Anything if it fails
withRamAnythingOnFail = lambda task: lambda: Conditional(main_task=Timeout(task(), 100), on_fail=RamAnything())
# Backs up and search for the triangular buoy again
SearchTriangleOnFail = lambda backspeed=0.2, backtime=10: Sequential(
Log('Failed, backing up'),
Zero(),
Timed(VelocityX(-backspeed), backtime),
Zero(),
Timeout(SearchTriangle(), 120))
SearchSingleOnFail = lambda backspeed=0.2, backtime=10: Sequential(
Log('backing up'),
Zero(),
Timed(VelocityX(-backspeed), backtime),
Zero(),
Timeout(SearchSingle(), 45))
# Decorator that wraps a task to search for the triangular buoy on fail
withSearchTriangleOnFail = lambda task: lambda: Retry(lambda: Conditional(main_task=task(), on_fail=Fail(SearchTriangleOnFail())), attempts=2)
withSearchSingleOnFail = lambda task: lambda: Retry(lambda: Conditional(main_task=task(), on_fail=Fail(SearchSingleOnFail())), attempts=2)
# Decorator that wraps a task to align to the buoy on fail
# Usually the task fails if it loses sight of the buoy, which means Align automatically fails and so search is run
withAlignAnyOnFail = lambda task: lambda: Retry(lambda: Conditional(main_task=task(), on_fail=Fail(AlignAnyNormal())), attempts=2)
withAlignSingleOnFail = lambda task: lambda: Retry(lambda: Conditional(main_task=task(), on_fail=Fail(AlignSingleNormal())), attempts=2)
SEARCH_SIZE_THRESH = 3000
# Task that searches for the triangular buoy
SearchTriangle = lambda stride=2: Sequential( #stride=1.25
Log('Searching for triangular buoy'),
SearchFor(
#SwaySearch(2.0, 0.7),
VelocitySwaySearch(stride=stride, width=2.5, rightFirst=get_sway_direction()),
lambda: triangle_visible(), # and any_buoy_size() > SEARCH_SIZE_THRESH,
consistent_frames=(1.7*60, 2.0*60) #TODO: Check consistent frames
),
FunctionTask(set_last_seen),
Log('Finish Search'),
Zero()
)
# @withRamAnythingOnFail
def SearchCalled():
return Sequential(
Log('Searching for any buoy'),
Zero(),
SearchFor(
While(lambda: VelocityY(DIRECTION * -0.2), True),
triangle_visible,
consistent_frames=(3, 5) #TODO: Check consistent frames
),
FunctionTask(set_last_seen),
Zero()
)
# Point = lambda px=0.3, py=0.0003, d=0.0005, db=0: Concurrent(
# HeadingTarget(point=any_buoy_center, target=CAM_CENTER, px=px, py=py, dy=d, dx=d, deadband=(db,db)),
# AlwaysLog(lambda: "center: {}, target: {}".format(CAM_CENTER, any_buoy_center())))
close_to = lambda point1, point2, dbx=20, dby=20: abs(point1[0]-point2[0]) < dbx and abs(point1[1]-point2[1]) < dby
aligned = lambda align, db=3: abs(align) < db
# Aligns horizontally with the buoy. It circles around the buoy using heading target and moving left/right relative to heading
def Align(centerf, alignf, visiblef, px=0.24, py=0.006, p=0.05, d=0.005, dx=0.3, dbx=20, dby=20, db=0):
return MasterConcurrent(
Consistent(lambda: close_to(centerf(), CAM_CENTER, dbx, dby) and aligned(alignf()), count=2.5, total=3.0, invert=False, result=True),
Consistent(visiblef, count=2.5, total=3.0, invert=True, result=False),
HeadingTarget(point=centerf, target=CAM_CENTER, px=px, py=py, dy=d, dx=dx, deadband=(db,db)),
PIDSway(alignf, p=p, d=d, db=db),
AlwaysLog(lambda: "align_h: %d"%(alignf(),)))
# Align with any side of the triangular buoy
@withSearchTriangleOnFail
def AlignAnyNormal():
return Align(centerf=any_buoy_center, alignf=align_any_h, visiblef=triangle_visible)
# Align only with the called side
@withReSearchCalledOnFail
def AlignCalledNormal():
return Align(centerf=call_buoy_center, alignf=align_call_h, visiblef=call_buoy_visible)
# Align with the single target buoy
@withSearchSingleOnFail
def AlignSingleNormal():
return Align(centerf=single_buoy_center, alignf=align_single_h, visiblef=single_buoy_visible, px=0.24, py=0.004, dx=0.3, dby=30)
# Centers the buoy using forward target
CenterBuoy = lambda centerf, visiblef, px=0.007, py=0.006, d=0.005, db=0: MasterConcurrent(
Consistent(lambda: close_to(centerf(), CAM_CENTER), count=2.7, total=3.0, invert=False, result=True),
#Consistent(visiblef, count=0.2, total=0.3, invert=True, result=False),
ForwardTarget(point=centerf, target=CAM_CENTER, px=px, py=py, dx=d, dy=d, deadband=(db,db)),
AlwaysLog(lambda: "center: {}, target: {}".format(CAM_CENTER, centerf())))
# Centers any side of the triangular buoy
CenterAnyBuoy = lambda: CenterBuoy(centerf=any_buoy_center, visiblef=triangle_visible)
# Centers only the called side
CenterCalledBuoy = lambda: CenterBuoy(centerf=call_buoy_center, visiblef=call_buoy_visible)
# Centers the single target buoy
CenterSingleBuoy = lambda: CenterBuoy(centerf=single_buoy_center, visiblef=single_buoy_visible)
# Approaches a the buoy until it reaches a predetermined size threshold
Approach = lambda sizef, centerf, visiblef: Sequential(
MasterConcurrent(Consistent(lambda: sizef() > SIZE_THRESH, count=0.2, total=0.3, invert=False, result=True), #ADD EITHER LOSE SIGHT OF BUOY
Consistent(visiblef, count=2.5, total=3.0, invert=True, result=False),
Succeed(VelocityX(.2)),
While(lambda: CenterBuoy(centerf=centerf, visiblef=visiblef), True),
AlwaysLog(lambda: "size: {}, visible: {}".format(sizef(), visiblef()))),
Zero())
# Approach only the called buoy
@withReSearchCalledOnFail
def ApproachCalled():
return Approach(sizef=call_buoy_size, centerf=call_buoy_center, visiblef=call_buoy_visible)
# Approach any side of the triangular buoy
@withAlignAnyOnFail
def ApproachAny():
return Approach(sizef=any_buoy_size, centerf=any_buoy_center, visiblef=triangle_visible)
# Approach the single target buoy
@withAlignSingleOnFail
def ApproachSingle():
return Approach(sizef=single_buoy_size, centerf=single_buoy_center, visiblef=single_buoy_visible)
# Don't use this because we are running the mission on minisub
Ram = lambda: Sequential(Concurrent(AlignAnyNormal(), MoveX(1)), Zero())
# Ram the buoy by approaching it until it is decently sized then moving forward a set amount of time
BIG_SIZE_THRESH = 10000
RamV = lambda: Sequential(Log('Ramming!'),
MasterConcurrent(
Consistent(lambda: any_buoy_size() > BIG_SIZE_THRESH, count=0.2, total=0.3, invert=False, result=True),
Succeed(CenterAnyBuoy()),
Succeed(VelocityX(.3))),
Log('yeet'),
Timed(VelocityX(0.3), 8),
Zero())
RamVSingle = lambda: Sequential(Log('Ramming!'),
MasterConcurrent(
Consistent(lambda: single_buoy_size() > BIG_SIZE_THRESH, count=0.2, total=0.3, invert=False, result=True),
Succeed(CenterSingleBuoy()),
Succeed(VelocityX(.3))),
Log('yeet'),
Timed(VelocityX(0.3), 8),
Zero())
# Search then approach the buoy
SearchAndApproach = lambda: Sequential(SearchCalled(), AlignCalledNormal(), ApproachCalled())# , AlignCalledNormal())
# The full mission for the triangular buoy
TriangleOnly = lambda: Sequential(
Log('Searching for buoy'),
Timeout(SearchCalled(), 30),
Log('Found buoy'),
ApproachAny(),
Log('Ramming'),
RamV(),
Log('Vamp_Buoy Complete'),
Heading(get_heading)
)
# Search task for the single target buoy
SearchSingle = lambda: Sequential(
Log('Searching for singular buoy'),
SearchFor(
VelocitySwaySearch(width=3, stride=4),
shm.vamp_buoy_results.jiangshi_visible.get,
# lambda: shm.vamp_buoy_results.jiangshi_visible.get() and single_buoy_size() > SEARCH_SIZE_THRESH,
consistent_frames=(3, 5)
),
Log('Singular Found'),
Zero()
)
DeadReckonStupid = lambda: \
Sequential(
# Timed(VelocityY(DIRECTION * 0.3, error=40), 3),
# VelocityY(0, error=40),
# Timed(VelocityX(0.3, error=40), 15),
# VelocityX(0, error=40),
# SlowHeading(),
Log('Backing up'),
Timed(VelocityX(-0.2), 6),
Log('finding buoy'),
RelativeToInitialHeading(DIRECTION * 90)
)
heading = None
def store_heading(h):
global heading
print('storing heading %s' % h())
heading = h()
def get_heading():
global heading
if heading == None:
heading = shm.kalman.heading.get()
print('getting heading %f' % heading)
return heading
# The full mission for the single target buoy
# TODO: Edge cases
SingleOnly = lambda: Sequential(
Timeout(SearchSingle(), 100),
FunctionTask(lambda: store_heading(shm.kalman.heading.get)),
ApproachSingle(),
RamVSingle(),
# SearchSingleOnFail(),
# Succeed(Timeout(AlignSingleNormal(), 20))
)
Full = lambda: Sequential(SingleOnly(), DeadReckonStupid(), TriangleOnly())
|
# -*- coding: utf-8 -*-
"""! OPM Config library.
@author zer0
@date 2015-12-16
"""
import xml.etree.ElementTree as ET
import xml.dom.minidom
import version as VER
TAG_ROOT = 'opm'
TAG_REMOTE = 'remote'
TAG_PROTOCOL = 'protocol'
TAG_USER = 'user'
TAG_HOST = 'host'
TAG_PORT = 'port'
TAG_PATH = 'path'
ATTR_VERSION = 'version'
ATTR_NAME = 'name'
DEFAULT_VERSION = VER.version()
DEFAULT_NAME = 'origin'
DEFAULT_PROTOCOL = 'sftp'
DEFAULT_USER = 'root'
DEFAULT_HOST = 'localhost'
DEFAULT_PORT = '22'
DEFAULT_PATH = '/var/opm'
class ConfigException(Exception):
"""! Config exception class.
@author zer0
@date 2015-12-04
"""
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
def appendElement(parent, tag, text):
child = ET.Element(tag)
child.text = text
parent.append(child)
# ------------
# XML Strings.
# ------------
def getConfigXmlString(version, name, protocol, user, host, port, path):
"""! Arguments -> XML String. """
tag_root = ET.Element(TAG_ROOT)
tag_root.set(ATTR_VERSION, version)
tag_remote = ET.Element(TAG_REMOTE)
tag_remote.set(ATTR_NAME, name)
tag_root.append(tag_remote)
appendElement(tag_remote, TAG_PROTOCOL, protocol)
appendElement(tag_remote, TAG_USER, user)
appendElement(tag_remote, TAG_HOST, host)
appendElement(tag_remote, TAG_PORT, port)
appendElement(tag_remote, TAG_PATH, path)
return ET.tostring(tag_root)
def getDefaultConfigXmlString():
"""! Default settings -> XML String. """
return getConfigXmlString(DEFAULT_VERSION,
DEFAULT_NAME,
DEFAULT_PROTOCOL,
DEFAULT_USER,
DEFAULT_HOST,
DEFAULT_PORT,
DEFAULT_PATH)
def getConfigXmlStringWithMap(config_map):
"""! Configure map -> XML String. """
return getConfigXmlString(config_map[ATTR_VERSION],
config_map[ATTR_NAME],
config_map[TAG_PROTOCOL],
config_map[TAG_USER],
config_map[TAG_HOST],
config_map[TAG_PORT],
config_map[TAG_PATH])
# ---------------
# Configure Maps.
# ---------------
def getConfigMap(version, name, protocol, user, host, port, path):
"""! Arguments -> Configure map. """
return {
ATTR_VERSION: version,
ATTR_NAME : name,
TAG_PROTOCOL: protocol,
TAG_USER : user,
TAG_HOST : host,
TAG_PORT : port,
TAG_PATH : path
}
def getDefaultConfigMap():
"""! Default settings -> Configure map. """
return getConfigMap(DEFAULT_VERSION,
DEFAULT_NAME,
DEFAULT_PROTOCOL,
DEFAULT_USER,
DEFAULT_HOST,
DEFAULT_PORT,
DEFAULT_PATH)
def getConfigMapWithInteractive():
"""! Interactive -> Configure map. """
version = DEFAULT_VERSION
name = raw_input('Remote name [{}]:'.format(DEFAULT_NAME))
protocol = raw_input('Protocol name [{}]:'.format(DEFAULT_PROTOCOL))
user = raw_input('User name [{}]:'.format(DEFAULT_USER))
host = raw_input('Host [{}]:'.format(DEFAULT_HOST))
port = raw_input('Port number [{}]:'.format(DEFAULT_PORT))
path = raw_input('Remote Path [{}]:'.format(DEFAULT_PATH))
if not name:
name = DEFAULT_NAME
if not protocol:
protocol = DEFAULT_PROTOCOL
if not user:
user = DEFAULT_USER
if not host:
host = DEFAULT_HOST
if not port:
port = DEFAULT_PORT
if not path:
path = DEFAULT_PATH
return getConfigMap(version, name, protocol, user, host, port, path)
# -------------
# XML File I/O.
# -------------
def writeConfigXmlWithMap(xml_path, config_map=None):
"""! Configure map -> XML file.
@param xml_path [in] XML file path.
@param config_map [in] Configure map.
"""
xml_body = ''
if config_map:
xml_body = getConfigXmlStringWithMap(config_map)
else:
xml_body = getDefaultConfigXmlString()
with open(xml_path, 'wb') as f:
f.write(xml.dom.minidom.parseString(xml_body).toprettyxml())
def readConfigXml(xml_path):
"""! XML file -> Configure map.
@param xml_path [in] XML file path.
@return Configure map.
"""
tag_root = ET.ElementTree().parse(xml_path)
# check the root tag.
if tag_root.tag != TAG_ROOT:
raise ConfigException('Not found {} tag.'.format(TAG_ROOT))
tag_remote = tag_root.find(TAG_REMOTE)
tag_protocol = tag_remote.find(TAG_PROTOCOL)
tag_user = tag_remote.find(TAG_USER)
tag_host = tag_remote.find(TAG_HOST)
tag_port = tag_remote.find(TAG_PORT)
tag_path = tag_remote.find(TAG_PATH)
return getConfigMap(tag_root.attrib[ATTR_VERSION],
tag_remote.attrib[ATTR_NAME],
tag_protocol.text,
tag_user.text,
tag_host.text,
tag_port.text,
tag_path.text)
# ------
# Class.
# ------
class Config(object):
"""! Configure class.
@author zer0
@date 2015-12-05
"""
def __init__(self, config_map=None):
if config_map:
self.config_map = config_map
def readConfigXml(self, xml_path):
self.config_map = readConfigXml(xml_path)
def setConfigMap(self, config_map):
self.config_map = config_map
def getVersion(self):
return self.config_map[ATTR_VERSION]
def getName(self):
return self.config_map[ATTR_NAME]
def getProtocol(self):
return self.config_map[TAG_PROTOCOL]
def getUser(self):
return self.config_map[TAG_USER]
def getHost(self):
return self.config_map[TAG_HOST]
def getPort(self):
return self.config_map[TAG_PORT]
def getPath(self):
return self.config_map[TAG_PATH]
def getUserOrInteractive(self):
user = self.getUser()
if not user:
return raw_input('User name:')
else:
return user
def getUri(self):
protocol = self.getProtocol()
host = self.getHost()
port = self.getPort()
path = self.getPath()
if path[0] != '/':
path = '/' + path
return '{}://{}:{}{}'.format(protocol, host, port, path)
if __name__ == '__main__':
pass
|
<gh_stars>0
import os
from moviepy.video.io.VideoFileClip import VideoFileClip
import numpy as np
from typing import Union
from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
from pydub import AudioSegment
from api.lib.gcp_transcibe import *
from api.lib.hangul_transform import *
from api.models import get_file_path, get_dir_path
AUDIO_FORMAT = ['.mp3']
VIDEO_FORMAT = ['.mp4']
SUPPORT_FORMAT = AUDIO_FORMAT + VIDEO_FORMAT
def get_filtered_file(file: Union[InMemoryUploadedFile, TemporaryUploadedFile], filename, format):
""" 오디오 파일을 받아 비속어 처리
@status `Active Review` \\
@params `file: Union[InMemoryUploadedFile, TemporaryUploadedFile]` \\
@params `format` \\
@returns `AudioSegment File` """
if format in VIDEO_FORMAT:
video = VideoFileClip(file.temporary_file_path())
audio = video.audio
FILE_DIR = os.path.join(settings.MEDIA_ROOT, get_file_path(None, f'{filename}.mp3'))
audio.write_audiofile(FILE_DIR)
file_path = FILE_DIR
else:
path = get_file_path(None, file.name)
file_path = default_storage.save(
os.path.join(settings.MEDIA_ROOT, path),
ContentFile(file.read())
)
sound = AudioSegment.from_file_using_temporary_files(file_path)
try:
response = transcribe_local(file_path)
timeline, swear_timeline, words = google_response(response)
print(f'timeline : {timeline}\n')
print(f'swear_timeline : {swear_timeline}\n')
print(f'words : {words}\n')
# deep
# ============================================================================
deep_swear_timeline = detect_swear(timeline=timeline, words=words)
swear_timeline = deep_swear_timeline
# swear_timeline = list(set(gcp_swear_timeline) & set(deep_swear_timeline)) # 테스트
# swear_timeline = list(set(gcp_swear_timeline) | set(deep_swear_timeline)) # 실사용
print(f'deep swear_timeline : {deep_swear_timeline}')
print(f'swear_timeline : {swear_timeline}')
# ============================================================================
# ============================================================================
# i = 0
# beep = create_beep(duration=1000)
# mixed = sound.overlay(beep, position=swear_timeline[i][0], gain_during_overlay=-50)
mixed_final = sound
for i in range(len(swear_timeline)):
beep = create_beep(duration=swear_timeline[i][1] - swear_timeline[i][0])
mixed_final = mixed_final.overlay(beep, position=swear_timeline[i][0], gain_during_overlay=-50)
# ============================================================================
'''
mixed_final.export(os.path.join(MEDIA_DIR, 'temp.mp3'), format='mp3')
video_clip = VideoFileClip(video_file.temporary_file_path(), audio=False)
print(video_clip)
video_clip: VideoFileClip = video_clip.set_audio(sound)
print(video_clip)
mixed_clip = video_clip.
video_clip.write_videofile(video_file.temporary_file_path(), \
codec='libx264',
audio_codec='aac',
temp_audiofile='temp-audio.m4a',
remove_temp=True
)
'''
except Exception as err:
print(err)
return mixed_final
def get_audio_with_meta(file: AudioSegment, filename: str, metadata: dict, format='mp3'):
"""오디오에 메타 데이터를 포함하여 파일을 생성하는 함수입니다.
@status `Accepted` \\
@params `file: AudioSegment` \\
@params `filename: str` \\
@params `metadata: dict` \\
@params `format: str` \\
@Returns `새로운 오디오 파일` """
FILE_DIR = os.path.join(settings.MEDIA_ROOT, get_dir_path())
file.export(os.path.join(FILE_DIR, f'{filename}.{format}'), format=format, tags=metadata)
return get_file_path(None, f'{filename}.{format}')
def get_metadata(validated_data: dict):
"""파일 메타 데이터 생성을 수행하는 함수입니다.
@status `Accepted` \\
@params `validated_data: dict` \\
@returns `메타 데이터 JSON 파일` """
metadata = {
"title": validated_data['title'],
'album': validated_data['album'],
"composer": validated_data['composer'],
"copyright": validated_data['copyright'],
}
return metadata
def create_beep(duration: int, sps: int=16000):
"""비프음 생성 함수입니다. sps은 `16khz`을 기본값으로 되어있으며 `durantion(ms)` 길이의 삐- 오디오를 생성합니다.
@status `Accepted` \\
@params `duration(ms): int` \\
@params `sps(hz): int=16000` \\
@returns `beep audio 파일` """
freq_hz = 1000.0
vol = 1
esm = np.arange(duration / 1000 * sps)
wf = np.sin(2 * np.pi * esm * freq_hz / sps)
wf_quiet = wf * vol
wf_int = np.int16(wf_quiet * 32767)
beep = AudioSegment(
wf_int.tobytes(),
frame_rate=sps,
sample_width=wf_int.dtype.itemsize,
channels=1
)
return beep |
<reponame>fantomnotabene/pyatv
"""Implementation of the MediaRemoteTV Protocol used by ATV4 and later."""
import logging
from .. import (const, exceptions)
from . import (messages, protobuf)
from .srp import SRPAuthHandler
from .connection import MrpConnection
from .protocol import MrpProtocol
from .pairing import MrpPairingProcedure
from ..interface import (AppleTV, RemoteControl, Metadata,
Playing, PushUpdater, PairingHandler)
_LOGGER = logging.getLogger(__name__)
# Source: https://github.com/Daij-Djan/DDHidLib/blob/master/usb_hid_usages.txt
_KEY_LOOKUP = {
# name: [usage_page, usage]
'up': [1, 0x8C],
'down': [1, 0x8D],
'left': [1, 0x8B],
'right': [1, 0x8A],
'play': [12, 0xB0],
'pause': [12, 0xB1],
'stop': [12, 0xB7],
'next': [12, 0xB5],
'previous': [12, 0xB6],
'select': [1, 0x89],
'menu': [1, 0x86],
'top_menu': [12, 0x60],
# 'mic': [12, 0x04] # Siri
}
class MrpRemoteControl(RemoteControl):
"""Implementation of API for controlling an Apple TV."""
def __init__(self, loop, protocol):
"""Initialize a new MrpRemoteControl."""
self.loop = loop
self.protocol = protocol
async def _press_key(self, key):
lookup = _KEY_LOOKUP.get(key, None)
if lookup:
await self.protocol.send(
messages.send_hid_event(lookup[0], lookup[1], True))
await self.protocol.send(
messages.send_hid_event(lookup[0], lookup[1], False))
else:
raise Exception('unknown key: ' + key)
def up(self):
"""Press key up."""
return self._press_key('up')
def down(self):
"""Press key down."""
return self._press_key('down')
def left(self):
"""Press key left."""
return self._press_key('left')
def right(self):
"""Press key right."""
return self._press_key('right')
def play(self):
"""Press key play."""
return self._press_key('play')
def pause(self):
"""Press key play."""
return self._press_key('pause')
def stop(self):
"""Press key stop."""
return self._press_key('stop')
def next(self):
"""Press key next."""
return self._press_key('next')
def previous(self):
"""Press key previous."""
return self._press_key('previous')
def select(self):
"""Press key select."""
return self._press_key('select')
def menu(self):
"""Press key menu."""
return self._press_key('menu')
def top_menu(self):
"""Go to main menu (long press menu)."""
return self._press_key('top_menu')
def set_position(self, pos):
"""Seek in the current playing media."""
raise exceptions.NotSupportedError
async def set_shuffle(self, is_on):
"""Change shuffle mode to on or off."""
raise exceptions.NotSupportedError
async def set_repeat(self, repeat_mode):
"""Change repeat mode."""
raise exceptions.NotSupportedError
class MrpPlaying(Playing):
"""Implementation of API for retrieving what is playing."""
def __init__(self, setstate, metadata):
"""Initialize a new MrpPlaying."""
self._setstate = setstate
self._metadata = metadata
@property
def media_type(self):
"""Type of media is currently playing, e.g. video, music."""
return const.MEDIA_TYPE_UNKNOWN
@property
def play_state(self):
"""Play state, e.g. playing or paused."""
# TODO: extract to a convert module
state = self._setstate.playbackState
if state == 1:
return const.PLAY_STATE_PLAYING
elif state == 2:
return const.PLAY_STATE_PAUSED
else:
raise exceptions.UnknownPlayState(
'Unknown playstate: ' + str(state))
@property
def title(self):
"""Title of the current media, e.g. movie or song name."""
return self._setstate.nowPlayingInfo.title or None
@property
def artist(self):
"""Artist of the currently playing song."""
return self._setstate.nowPlayingInfo.artist or None
@property
def album(self):
"""Album of the currently playing song."""
return self._setstate.nowPlayingInfo.album or None
@property
def genre(self):
"""Genre of the currently playing song."""
return None
@property
def total_time(self):
"""Total play time in seconds."""
now_playing = self._setstate.nowPlayingInfo
if now_playing.HasField('duration'):
return int(now_playing.duration)
return None
@property
def position(self):
"""Position in the playing media (seconds)."""
now_playing = self._setstate.nowPlayingInfo
if now_playing.HasField('elapsedTime'):
return int(now_playing.elapsedTime)
return None
@property
def shuffle(self):
"""If shuffle is enabled or not."""
return None
@property
def repeat(self):
"""Repeat mode."""
return None
class MrpMetadata(Metadata):
"""Implementation of API for retrieving metadata."""
def __init__(self, protocol):
"""Initialize a new MrpPlaying."""
self.protocol = protocol
self.protocol.add_listener(
self._handle_set_state, protobuf.SET_STATE_MESSAGE)
self.protocol.add_listener(
self._handle_transaction, protobuf.TRANSACTION_MESSAGE)
self._setstate = None
self._nowplaying = None
async def _handle_set_state(self, message, _):
self._setstate = message.inner()
async def _handle_transaction(self, message, _):
packet = message.inner().packets[0].packet
self._nowplaying = packet.contentItem.metadata.nowPlayingInfo
@property
def device_id(self):
"""Return a unique identifier for current device."""
raise exceptions.NotSupportedError
async def artwork(self):
"""Return artwork for what is currently playing (or None)."""
raise exceptions.NotSupportedError
async def artwork_url(self):
"""Return artwork URL for what is currently playing."""
raise exceptions.NotSupportedError
async def playing(self):
"""Return what is currently playing."""
# TODO: This is hack-ish
if self._setstate is None:
await self.protocol.start()
# No SET_STATE_MESSAGE received yet, use default
if self._setstate is None:
return MrpPlaying(protobuf.SetStateMessage(), None)
return MrpPlaying(self._setstate, self._nowplaying)
class MrpPushUpdater(PushUpdater):
"""Implementation of API for handling push update from an Apple TV."""
def __init__(self, loop, metadata, protocol):
"""Initialize a new MrpPushUpdater instance."""
super().__init__()
self.loop = loop
self.metadata = metadata
self.protocol = protocol
self.protocol.add_listener(
self._handle_update, protobuf.SET_STATE_MESSAGE)
self.protocol.add_listener(
self._handle_update, protobuf.TRANSACTION_MESSAGE)
self._enabled = False
def start(self, initial_delay=0):
"""Wait for push updates from device.
Will throw NoAsyncListenerError if no listner has been set.
"""
if self.listener is None:
raise exceptions.NoAsyncListenerError
elif self._enabled:
return
self._enabled = True
def stop(self):
"""No longer wait for push updates."""
self._enabled = False
async def _handle_update(self, *_):
if self._enabled:
playstatus = await self.metadata.playing()
self.loop.call_soon(
self.listener.playstatus_update, self, playstatus)
class MrpPairingHandler(PairingHandler):
"""Base class for API used to pair with an Apple TV."""
def __init__(self, protocol, srp, service):
"""Initialize a new MrpPairingHandler."""
self.pairing_procedure = MrpPairingProcedure(protocol, srp)
self.service = service
@property
def has_paired(self):
"""If a successful pairing has been performed."""
return self.service.device_credentials is not None
async def start(self, **kwargs):
"""Start pairing process."""
await self.pairing_procedure.start_pairing()
async def stop(self, **kwargs):
"""Stop pairing process."""
pin = kwargs['pin']
self.service.device_credentials = \
await self.pairing_procedure.finish_pairing(pin)
async def set(self, key, value, **kwargs):
"""Set a process specific value.
The value is specific to the device being paired with and can for
instance be a PIN code.
"""
raise exceptions.NotSupportedError
async def get(self, key):
"""Retrieve a process specific value."""
if key == 'credentials' and self.service.device_credentials:
return str(self.service.device_credentials)
return None
class MrpAppleTV(AppleTV):
"""Implementation of API support for Apple TV."""
# This is a container class so it's OK with many attributes
# pylint: disable=too-many-instance-attributes
def __init__(self, loop, session, details, airplay):
"""Initialize a new Apple TV."""
super().__init__()
self._session = session
self._mrp_service = details.usable_service()
self._connection = MrpConnection(
details.address, self._mrp_service.port, loop)
self._srp = SRPAuthHandler()
self._protocol = MrpProtocol(
loop, self._connection, self._srp, self._mrp_service)
self._mrp_remote = MrpRemoteControl(loop, self._protocol)
self._mrp_metadata = MrpMetadata(self._protocol)
self._mrp_push_updater = MrpPushUpdater(
loop, self._mrp_metadata, self._protocol)
self._mrp_pairing = MrpPairingHandler(
self._protocol, self._srp, self._mrp_service)
self._airplay = airplay
async def login(self):
"""Perform an explicit login."""
await self._protocol.start()
async def logout(self):
"""Perform an explicit logout.
Must be done when session is no longer needed to not leak resources.
"""
await self._session.close()
self._protocol.stop()
@property
def service(self):
"""Return service used to connect to the Apple TV.."""
return self._mrp_service
@property
def pairing(self):
"""Return API for pairing with the Apple TV."""
return self._mrp_pairing
@property
def remote_control(self):
"""Return API for controlling the Apple TV."""
return self._mrp_remote
@property
def metadata(self):
"""Return API for retrieving metadata from Apple TV."""
return self._mrp_metadata
@property
def push_updater(self):
"""Return API for handling push update from the Apple TV."""
return self._mrp_push_updater
@property
def airplay(self):
"""Return API for working with AirPlay."""
return self._airplay
|
from typing import *
from gym import Env, spaces
import numpy as np
from numba import njit
import ray
from ray.tune.logger import pretty_print
from ray.rllib.env import BaseEnv
from ray.rllib.agents.trainer import Trainer
from ray.rllib.agents.callbacks import DefaultCallbacks
from ray.rllib.models import ModelCatalog, MODEL_DEFAULTS
from ray.rllib.policy import Policy
from ray.rllib.policy.tf_policy import TFPolicy
from ray.rllib.policy.torch_policy import TorchPolicy
from ray.rllib.utils.typing import AgentID, PolicyID, TensorType
from ray.rllib.evaluation.episode import Episode
from ray.rllib.utils.schedules.schedule import Schedule
from kodoku.env import EnvWrapper
class LogCallbacks(DefaultCallbacks):
log_dict = {}
reward_dict = {}
def __init__(self):
super().__init__()
self.reset()
def log(self) -> Dict:
return LogCallbacks.log_dict
def reward(self) -> Dict[int,Dict]:
return LogCallbacks.reward_dict
def reset(self) -> None:
LogCallbacks.log_dict = {}
LogCallbacks.reward_dict = {}
def common_callback(self, base_env: BaseEnv, env_index: int = None, **kwargs):
ei : int = env_index if env_index is not None else 0
envs : List[EnvWrapper] = base_env.get_sub_environments()
scenario_name : str = envs[ei].scenario_name
if scenario_name not in LogCallbacks.log_dict:
LogCallbacks.log_dict[scenario_name] = {}
if ei not in LogCallbacks.log_dict[scenario_name]:
LogCallbacks.log_dict[scenario_name][ei] = []
return envs[ei], scenario_name, ei
def on_episode_start(self, *, worker: "RolloutWorker", base_env: BaseEnv,
policies: Dict[PolicyID, Policy], episode: Episode,
**kwargs) -> None:
env, scenario_name, ei = self.common_callback(base_env, **kwargs)
LogCallbacks.log_dict[scenario_name][ei].append([])
LogCallbacks.log_dict[scenario_name][ei][-1].append(env.log())
def on_episode_step(self, *, worker: "RolloutWorker", base_env: BaseEnv,
policies: Dict[PolicyID, Policy], episode: Episode,
**kwargs) -> None:
env, scenario_name, ei = self.common_callback(base_env, **kwargs)
if len(LogCallbacks.log_dict[scenario_name][ei]) == 0:
LogCallbacks.log_dict[scenario_name][ei].append([])
LogCallbacks.log_dict[scenario_name][ei][-1].append(env.log())
def on_episode_end(self, *, worker: "RolloutWorker", base_env: BaseEnv,
policies: Dict[PolicyID, Policy], episode: Episode,
**kwargs) -> None:
LogCallbacks.reward_dict[episode.episode_id] = episode.agent_rewards
def print_network_architecture(trainer : Trainer, policies : List[str]) -> None:
""" Print network architectures for policies
Args:
trainer (Trainer): Trainer object
policies (List[str]): Policies to print
"""
for policy_name in policies:
print(policy_name, "Network Architecture")
policy = trainer.get_policy(policy_name)
if policy is not None:
if isinstance(policy, TorchPolicy):
print(policy.model)
elif isinstance(policy, TFPolicy):
policy.model.base_model.summary()
else:
print('Unknown framework:', policy)
else:
print('Policy for %s is None' % policy_name)
class ScheduleScaler(Schedule):
def __init__(self, schedule : Schedule, scale : float = 1.0):
""" Schedule scaler
This class wraps existing schedule instance to scale its value
Args:
schedule (Schedule): Schedule instance
scale (float, optional): Scale
"""
self.schedule = schedule
self.scale = scale
self.framework = schedule.framework
def _value(self, t: Union[int, TensorType]) -> Any:
return self.schedule(t) * self.scale
|
#!/usr/bin/env python
import rospy
from time import sleep
from smach import State, StateMachine
from nav_msgs.msg import Odometry
from smach_ros import SimpleActionState, IntrospectionServer
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from vortex_msgs.msg import LosPathFollowingAction, LosPathFollowingGoal
# Imported help functions from src/finite_state_machine
from finite_state_machine import ControllerMode, WaypointClient, PathFollowingClient
#ENUM
OPEN_LOOP = 0
POSE_HOLD = 1
HEADING_HOLD = 2
DEPTH_HEADING_HOLD = 3
DEPTH_HOLD = 4
STAY_LEVEL = 5
CONTROL_MODE_END = 6
class Mission():
def __init__(self):
# ros init
rospy.init_node('mission_fsm', anonymous=True)
# rate
self.rate = rospy.Rate(100) #Hz
class Vehicle():
def __init__(self):
# Subscriber
self.sub = rospy.Subscriber('/odometry/filtered', Odometry, self.positionCallback, queue_size=1)
def positionCallback(self, msg):
self.vehicle = msg
class ControlMode(State):
def __init__(self, mode):
State.__init__(self, outcomes=['success'])
self.mode = mode
self.control_mode = ControllerMode()
def execute(self, userdata):
# change control mode
self.control_mode.change_control_mode_client(self.mode)
return 'success'
class Drive(State):
def __init__(self, distance):
State.__init__(self,outcomes=['succeeded','aborted','preempted'])
self.distance = distance
def execute(self, userdata):
print 'Driving', self.distance
sleep(1)
return 'succeeded'
class Turn(State):
def __init__(self, angle):
State.__init__(self, outcomes=['succeeded','aborted','preempted'])
self.angle = angle
def execute(self, userdata):
print 'Turning', self.angle
sleep(1)
return 'succeeded'
if __name__ == '__main__':
try:
mission = Mission()
vehicle = Vehicle()
wpc = WaypointClient()
los = PathFollowingClient()
except rospy.ROSInterruptException:
rospy.loginfo("Unable to run constructor")
# possible transitions
patrol = StateMachine(['succeeded','aborted','preempted'])
with patrol:
waypoints = [['one', (20.0, -2.0, -0.75), (0.0, 0.0, 0.0)],
['two', (24.0, -2.0, -0.75), (0.0, 0.0, 1.57)]]
# Adding the states and transitions
StateMachine.add('POSE_HOLD', ControlMode(POSE_HOLD), transitions={'success':'POSE_HOLD - ' + waypoints[0][0]})
StateMachine.add('POSE_HOLD - ' + waypoints[0][0], SimpleActionState('move_base',MoveBaseAction,goal=wpc.trackNewWaypoint(waypoints[0])),transitions={'succeeded':'POSE_HOLD - ' + waypoints[1][0]})
StateMachine.add('POSE_HOLD - ' + waypoints[1][0], SimpleActionState('move_base',MoveBaseAction,goal=wpc.trackNewWaypoint(waypoints[1])),transitions={'succeeded':'DEPTH_HOLD'})
StateMachine.add('DEPTH_HOLD', ControlMode(DEPTH_HEADING_HOLD), transitions={'success':'DEPTH_HOLD - ' + waypoints[1][0]})
StateMachine.add('DEPTH_HOLD - ' + waypoints[1][0], SimpleActionState('move_base',MoveBaseAction,goal=wpc.trackNewWaypoint(waypoints[1])),transitions={'succeeded':'OPEN_LOOP'})
StateMachine.add('OPEN_LOOP', ControlMode(OPEN_LOOP), transitions={'success':'succeeded'})
# Define outcomes
square = StateMachine(outcomes=['succeeded', 'preempted', 'aborted'])
# State machine square
with square:
StateMachine.add('SIDE1', Drive(1), transitions={'succeeded':'TURN1'})
StateMachine.add('TURN1', Turn(90), transitions={'succeeded':'SIDE2', 'preempted':'TURN2'})
StateMachine.add('SIDE2', Drive(1), transitions={'succeeded':'TURN2'})
StateMachine.add('TURN2', Turn(90), transitions={'succeeded':'SIDE3'})
StateMachine.add('SIDE3', Drive(1), transitions={'succeeded':'TURN3'})
StateMachine.add('TURN3', Turn(90), transitions={'succeeded':'SIDE4'})
StateMachine.add('SIDE4', Drive(1), transitions={'succeeded':'succeeded'})
# Define transit state
transit = StateMachine(outcomes=['succeeded', 'preempted', 'aborted'])
_goal = los.path_client(0, 0, 16, -2, 0.2, 0.5)
# State machine
with transit:
StateMachine.add('transit', SimpleActionState('los_path',LosPathFollowingAction, goal=_goal), transitions={'succeeded':'succeeded'})
# Define outcomes
shapes = StateMachine(outcomes=['succeeded', 'preempted', 'aborted', 'completed'])
# Creating a hierarchical state machine nesting several sm's
with shapes:
StateMachine.add('transit', transit, transitions={'succeeded':'square'})
StateMachine.add('square', square, transitions={'succeeded':'terminal'})
StateMachine.add('terminal', patrol, transitions={'succeeded':'completed'})
sis = IntrospectionServer(str(rospy.get_name()), shapes, '/SM_ROOT' + str(rospy.get_name()))
sis.start()
shapes.execute()
rospy.spin()
sis.stop()
|
import os
from ctypes import (
addressof,
byref,
c_char,
c_double,
c_int,
c_long,
c_longlong,
c_ubyte,
c_ushort,
create_string_buffer,
pointer,
string_at,
)
from assertpy import assert_that, soft_assertions
import gsfpy3_09.bindings
import gsfpy3_09.enums
from gsfpy3_09.constants import GSF_MAX_PING_ARRAY_SUBRECORDS
from gsfpy3_09.enums import (
FileMode,
PingFlag,
RecordType,
ScaledSwathBathySubRecord,
SeekOption,
)
from gsfpy3_09.GSF_POSITION import c_GSF_POSITION
from gsfpy3_09.GSF_POSITION_OFFSETS import c_GSF_POSITION_OFFSETS
from gsfpy3_09.gsfDataID import c_gsfDataID
from gsfpy3_09.gsfMBParams import c_gsfMBParams
from gsfpy3_09.gsfRecords import c_gsfRecords
from gsfpy3_09.gsfScaleFactors import c_gsfScaleFactors
from gsfpy3_09.gsfSwathBathyPing import c_gsfSwathBathyPing
def test_gsfOpenClose_success(gsf_test_data_03_09):
"""
Open the test GSF file, then close.
"""
file_handle = c_int(0)
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
def test_gsfOpenBuffered_success(gsf_test_data_03_09):
"""
Open the test GSF file, then close.
"""
file_handle = c_int(0)
buf_size = 100
return_value = gsfpy3_09.bindings.gsfOpenBuffered(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
buf_size,
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
def test_gsfSeek_success(gsf_test_data_03_09):
"""
Open the test GSF file, seek to end of file, then close.
"""
file_handle = c_int(0)
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfSeek(file_handle, SeekOption.GSF_END_OF_FILE)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
def test_gsfError_non_existent_file(gsf_test_data_03_09):
"""
Try to open a non-existent GSF file and check that gsfError() returns the
correct error code and error message.
"""
file_handle = c_int(0)
return_value = gsfpy3_09.bindings.gsfOpen(
b"non-existent.gsf", FileMode.GSF_READONLY, byref(file_handle)
)
assert_that(return_value).is_not_zero()
with soft_assertions():
return_value = gsfpy3_09.bindings.gsfIntError()
assert_that(return_value).described_as(
"Error code for 'GSF Error: Unable to open requested file'"
).is_equal_to(-1)
string_error = gsfpy3_09.bindings.gsfStringError()
assert_that(string_error).is_equal_to(
b"GSF Error: Unable to open requested file"
)
def test_gsfError_operation_in_wrong_file_mode(gsf_test_data_03_09):
"""
Open a GSF file, try to get the number of GSF and check that gsfError() returns the
correct error code and error message.
"""
file_handle = c_int(0)
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfGetNumberRecords(
file_handle, RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING
)
assert_that(return_value).is_not_zero()
with soft_assertions():
return_value = gsfpy3_09.bindings.gsfIntError()
assert_that(return_value).described_as(
"Error code for 'GSF Error: Illegal access mode'"
).is_equal_to(-3)
string_error = gsfpy3_09.bindings.gsfStringError()
assert_that(string_error).is_equal_to(b"GSF Error: Illegal access mode")
def test_gsfRead_success(gsf_test_data_03_09):
"""
Read a comment record from a GSF file.
"""
file_handle = c_int(0)
data_id = c_gsfDataID()
records = c_gsfRecords()
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle, RecordType.GSF_RECORD_COMMENT, byref(data_id), byref(records),
)
assert_that(bytes_read).is_equal_to(32)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
assert_that(string_at(records.comment.comment)).is_equal_to((b"My comment"))
def test_gsfWrite_success(tmp_path):
"""
Write a single comment record to a new GSF file
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
data_id.recordID = RecordType.GSF_RECORD_COMMENT
comment = b"My first comment"
records = c_gsfRecords()
records.comment.comment_time.tvsec = c_int(1000)
records.comment.comment_length = c_int(len(comment))
records.comment.comment = create_string_buffer(comment)
record_size = 36 # bytes
tmp_gsf_file_path = os.fsencode(str(tmp_path / "temp.gsf"))
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
tmp_gsf_file_path, FileMode.GSF_CREATE, byref(file_handle)
)
assert_that(return_value).is_zero()
bytes_written = gsfpy3_09.bindings.gsfWrite(
file_handle, byref(data_id), byref(records)
)
assert_that(bytes_written).is_equal_to(record_size)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Read comment from newly created file to check it is as expected
data_id = c_gsfDataID()
data_id.recordID = RecordType.GSF_RECORD_COMMENT
records = c_gsfRecords()
return_value = gsfpy3_09.bindings.gsfOpen(
tmp_gsf_file_path, FileMode.GSF_READONLY, byref(file_handle)
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle, RecordType.GSF_RECORD_COMMENT, byref(data_id), byref(records),
)
assert_that(bytes_read).is_equal_to(record_size)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
assert_that(string_at(records.comment.comment)).is_equal_to(comment)
def test_gsfGetNumberRecords_success(gsf_test_data_03_09):
"""
Open the test GSF file, count the number of GSF_RECORD_SWATH_BATHYMETRY_PING
records, then close.
"""
file_handle = c_int(0)
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY_INDEX,
byref(file_handle),
)
assert_that(return_value).is_zero()
number_of_records = gsfpy3_09.bindings.gsfGetNumberRecords(
file_handle, RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING
)
assert_that(number_of_records).is_equal_to(3)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
def test_gsfIndexTime_success(gsf_test_data_03_09):
"""
Open the test GSF file, get the index time and record number of the last
multibeam ping record.
"""
file_handle = c_int(0)
sec = c_int(-1)
nsec = c_long(-1)
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY_INDEX,
byref(file_handle),
)
assert_that(return_value).is_zero()
index_time = gsfpy3_09.bindings.gsfIndexTime(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
c_int(-1),
byref(sec),
byref(nsec),
)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
with soft_assertions():
assert_that(index_time).is_equal_to(3)
assert_that(sec.value).is_equal_to(1541193704)
assert_that(nsec.value).is_equal_to(559999465)
def test_gsfPercent_success(gsf_test_data_03_09):
"""
Open the test GSF file, read 4 records, then retrieve the location of the file
pointer as a percentage of the total file size.
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
records = c_gsfRecords()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY_INDEX,
byref(file_handle),
)
assert_that(return_value).is_zero()
for i in range(4):
gsfpy3_09.bindings.gsfRead(
file_handle, RecordType.GSF_NEXT_RECORD, byref(data_id), byref(records)
)
percent = gsfpy3_09.bindings.gsfPercent(file_handle)
assert_that(percent).is_equal_to(76)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
def test_gsfGetSwathBathyBeamWidths_success(gsf_test_data_03_09):
"""
Open the test GSF file, read a multibeam ping record, then get fore-aft and
port-starboard beam widths, in degrees, for the given ping.
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
records = c_gsfRecords()
fore_aft = c_double()
athwartship = c_double()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
return_value = gsfpy3_09.bindings.gsfGetSwathBathyBeamWidths(
byref(records), byref(fore_aft), byref(athwartship),
)
# There is nsufficient info in the test file to calculate beam widths
assert_that(return_value).is_equal_to(-1)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
assert_that(fore_aft.value).is_equal_to(-1.0) # GSF_BEAM_WIDTH_UNKNOWN
assert_that(athwartship.value).is_equal_to(-1.0) # GSF_BEAM_WIDTH_UNKNOWN
def test_gsfGetSwathBathyArrayMinMax_success(gsf_test_data_03_09):
"""
Open the test GSF file, read a multibeam ping record, then get min and
max supportable values for the swath bathymetry arrays in the given ping.
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
records = c_gsfRecords()
min_value = c_double()
max_value = c_double()
subrecord_id = c_int(1)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
return_value = gsfpy3_09.bindings.gsfGetSwathBathyArrayMinMax(
byref(records.mb_ping), subrecord_id, byref(min_value), byref(max_value),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
assert_that(min_value.value).is_equal_to(0.0)
assert_that(max_value.value).is_equal_to(655.35)
def test_gsfIsStarboardPing_success(gsf_test_data_03_09):
"""
Open the test GSF file, read a multibeam ping record, then find out if
it is a starboard ping.
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
records = c_gsfRecords()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
is_starboard_ping: int = gsfpy3_09.bindings.gsfIsStarboardPing(byref(records))
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(is_starboard_ping).is_false()
def test_gsfGetSonarTextName_success(gsf_test_data_03_09):
"""
Open the test GSF file, read a multibeam ping record, then retrieve
the name of the sonar equipment used to capture it.
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
records = c_gsfRecords()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
sonar_text_name = gsfpy3_09.bindings.gsfGetSonarTextName(byref(records.mb_ping))
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(sonar_text_name).is_equal_to("Unknown")
def test_gsfFileSupportsRecalculateXYZ_success(gsf_test_data_03_09):
"""
Open the test GSF file then discover whether it contains enough information
for platform-relative XYZ values to be recalculated.
"""
# Arrange
file_handle = c_int(0)
status = c_int(0)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfFileSupportsRecalculateXYZ(
file_handle, byref(status)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(status.value).is_false()
def test_gsfFileSupportsRecalculateTPU_success(gsf_test_data_03_09):
"""
Open the test GSF file then discover whether it contains enough information
for Total Propagated Uncertainty (TPU) values to be calculated.
"""
# Arrange
file_handle = c_int(0)
status = c_int(0)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfFileSupportsRecalculateTPU(
file_handle, byref(status)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(status.value).is_equal_to(0)
def test_gsfFileSupportsRecalculateNominalDepth_success(gsf_test_data_03_09):
"""
Open the test GSF file then discover whether it contains enough information
for the nominal depth array to be calculated.
"""
# Arrange
file_handle = c_int(0)
status = c_int(0)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfFileSupportsRecalculateNominalDepth(
file_handle, byref(status)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(status.value).is_equal_to(0)
def test_gsfFileContainsMBAmplitude_success(gsf_test_data_03_09):
"""
Open the test GSF file then discover whether it contains amplitude data.
"""
# Arrange
file_handle = c_int(0)
status = c_int(0)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfFileContainsMBAmplitude(
file_handle, byref(status)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(status.value).is_equal_to(0)
def test_gsfFileContainsMBImagery_success(gsf_test_data_03_09):
"""
Open the test GSF file then discover whether it contains beam imagery.
"""
# Arrange
file_handle = c_int(0)
status = c_int(0)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfFileContainsMBImagery(
file_handle, byref(status)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(status.value).is_equal_to(0)
def test_gsfFileIsNewSurveyLine_success(gsf_test_data_03_09):
"""
Open the test GSF file, read a ping, then discover whether it comes
from a new survey line.
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
records = c_gsfRecords()
azimuth_change = c_double(90)
last_heading = c_double(1)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
is_new_survey_line: int = gsfpy3_09.bindings.gsfIsNewSurveyLine(
file_handle, byref(records), azimuth_change, byref(last_heading)
)
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
assert_that(is_new_survey_line).is_true()
def test_gsfInitializeMBParams_success(gsf_test_data_03_09):
"""
Create a gsfMBParams structure and initialize all fields.
"""
# Arrange
mbparams = c_gsfMBParams()
# Act
gsfpy3_09.bindings.gsfInitializeMBParams(byref(mbparams))
# Assert two of the fields here to check they are set to the unknown
# value.
with soft_assertions():
assert_that(mbparams.horizontal_datum).is_equal_to(-99)
# vessel_type Defaults to GSF_PLATFORM_TYPE_SURFACE_SHIP instead of
# GSF_UNKNOWN_PARAM_INT from GSF v3.09 onwards
assert_that(mbparams.vessel_type).is_equal_to(0)
def test_gsfCopyRecords_success(gsf_test_data_03_09):
"""
Open the test GSF file, read a record, then copy the contents to
a new gsfRecords structure.
"""
# Arrange
file_handle = c_int(0)
data_id = c_gsfDataID()
source_records = c_gsfRecords()
target_records = c_gsfRecords()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_COMMENT,
byref(data_id),
byref(source_records),
)
assert_that(bytes_read).is_equal_to(32)
return_value = gsfpy3_09.bindings.gsfCopyRecords(
pointer(target_records), pointer(source_records)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
assert_that(target_records.comment.comment_time.tv_sec).is_equal_to(
source_records.comment.comment_time.tv_sec
)
assert_that(target_records.comment.comment_time.tv_nsec).is_equal_to(
source_records.comment.comment_time.tv_nsec
)
assert_that(target_records.comment.comment_length).is_equal_to(
source_records.comment.comment_length
)
assert_that(addressof(target_records.comment.comment)).is_not_equal_to(
addressof(source_records.comment.comment)
)
assert_that(string_at(target_records.comment.comment)).is_equal_to(
string_at(source_records.comment.comment)
)
def test_gsfPutMBParams_success(gsf_test_data_03_09):
"""
Create a gsfMBParams structure and copy fields to a gsfRecords
structure.
"""
# Arrange
mbparams = c_gsfMBParams()
gsfpy3_09.bindings.gsfInitializeMBParams(byref(mbparams))
# Only WGS-84 (57) and NAD-83 (38) horizontal datum values are
# supported by GSF - see gsf.h
mbparams.horizontal_datum = c_int(57)
# Set number_of_transmitters and number_of_receivers to zero
# so that num_arrays param is used for these values when
# setting the params in the gsfRecords structure.
mbparams.number_of_transmitters = c_int(0)
mbparams.number_of_receivers = c_int(0)
mbparams.to_apply.position_x_offset = c_double(1.1)
mbparams.to_apply.position_y_offset = c_double(2.2)
mbparams.to_apply.position_z_offset = c_double(3.3)
mbparams.applied.position_x_offset = c_double(4.4)
mbparams.applied.position_y_offset = c_double(5.5)
mbparams.applied.position_z_offset = c_double(6.6)
records = c_gsfRecords()
# data_id = c_gsfDataID()
file_handle = c_int(0)
num_arrays = c_int(1)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfPutMBParams(
byref(mbparams), byref(records), file_handle, num_arrays
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
assert_that(records.process_parameters.number_parameters).is_equal_to(63)
# param zero is always epoch start time
assert_that(string_at(records.process_parameters.param[0])).is_equal_to(
b"REFERENCE TIME=1970/001 00:00:00"
)
# params 7 (NUMBER_OF_RECEIVERS) & 8 (NUMBER_OF_TRANSMITTERS) should have
# a value equal to num_arrays
assert_that(string_at(records.process_parameters.param[7])).is_equal_to(
b"NUMBER_OF_RECEIVERS=1"
)
assert_that(string_at(records.process_parameters.param[8])).is_equal_to(
b"NUMBER_OF_TRANSMITTERS=1"
)
# param 9 (DEPTH_CALCULATION) should have a value of 'UNKNOWN' as it
# has not been updated since being initialized
assert_that(string_at(records.process_parameters.param[9])).is_equal_to(
b"DEPTH_CALCULATION=UNKNOWN"
)
# param 19 (POSITION_OFFSET_TO_APPLY) should have values x,y,z equal to
# corresponding values in mbparams.to_apply
assert_that(string_at(records.process_parameters.param[19])).is_equal_to(
b"POSITION_OFFSET_TO_APPLY=+01.10,+02.20,+03.30"
)
# param 42 (APPLIED_POSITION_OFFSET) should have values x,y,z equal to
# corresponding values in mbparams.to_apply
assert_that(string_at(records.process_parameters.param[42])).is_equal_to(
b"APPLIED_POSITION_OFFSET=+04.40,+05.50,+06.60"
)
# param 61 (GEOID) should have a value equal to WGS-84, corresponding to
# mbparams.horizontal_datum value of 57
assert_that(string_at(records.process_parameters.param[61])).is_equal_to(
b"GEOID=WGS-84"
)
def test_gsfGetMBParams_success(gsf_test_data_03_09):
"""
Set MB params, read a GSF record and copy fields to a gsfMBParams
structure.
"""
# Arrange
mbparams_in = c_gsfMBParams()
gsfpy3_09.bindings.gsfInitializeMBParams(byref(mbparams_in))
mbparams_in.horizontal_datum = c_int(57)
mbparams_out = c_gsfMBParams()
gsfpy3_09.bindings.gsfInitializeMBParams(byref(mbparams_out))
records = c_gsfRecords()
data_id = c_gsfDataID()
file_handle = c_int(0)
num_arrays = c_int(1)
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfPutMBParams(
byref(mbparams_in), byref(records), file_handle, num_arrays
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
return_value = gsfpy3_09.bindings.gsfGetMBParams(
byref(records), byref(mbparams_out), byref(num_arrays)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
assert_that(mbparams_out.horizontal_datum).is_equal_to(
mbparams_in.horizontal_datum
)
assert_that(mbparams_out.number_of_transmitters).is_equal_to(1)
assert_that(mbparams_out.number_of_receivers).is_equal_to(1)
def test_gsfStat_success(gsf_test_data_03_09):
"""
Get the size in bytes of a GSF file.
"""
# Arrange
sz = c_longlong(0)
# Act
return_value = gsfpy3_09.bindings.gsfStat(
os.fsencode(str(gsf_test_data_03_09.path)), byref(sz)
)
assert_that(return_value).is_zero()
# Assert
assert_that(sz.value).is_equal_to(432)
def test_gsfLoadScaleFactor_success(gsf_test_data_03_09):
"""
Create a gsfScaleFactors structure and initialize all fields.
"""
# Arrange
scaleFactors = c_gsfScaleFactors()
subrecord_id = (
ScaledSwathBathySubRecord.GSF_SWATH_BATHY_SUBRECORD_SONAR_VERT_UNCERT_ARRAY
)
# Save as two byte value after applying scale and offset
c_flag = c_char(0x20)
# 1cm precision for depth
precision = c_double(0.01)
offset = c_int(4)
# Act
return_value = gsfpy3_09.bindings.gsfLoadScaleFactor(
byref(scaleFactors), subrecord_id, c_flag, precision, offset
)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
index = subrecord_id.value - 1
assert_that(len(scaleFactors.scaleTable)).is_equal_to(
GSF_MAX_PING_ARRAY_SUBRECORDS
)
assert_that(int(scaleFactors.scaleTable[index].compressionFlag)).is_equal_to(32)
assert_that(int(scaleFactors.scaleTable[index].multiplier)).is_equal_to(
1 / precision.value
)
assert_that(int(scaleFactors.scaleTable[index].offset)).is_equal_to(
offset.value
)
def test_gsfGetScaleFactor_success(gsf_test_data_03_09):
"""
Read a GSF record and get the beam array field size, compression flag,
multiplier and DC offset applied to it.
"""
# Arrange
file_handle = c_int(0)
records = c_gsfRecords()
data_id = c_gsfDataID()
subrecord_id = ScaledSwathBathySubRecord.GSF_SWATH_BATHY_SUBRECORD_BEAM_FLAGS_ARRAY
c_flag = c_ubyte()
multiplier = c_double()
offset = c_double()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
return_value = gsfpy3_09.bindings.gsfGetScaleFactor(
file_handle, subrecord_id, byref(c_flag), byref(multiplier), byref(offset)
)
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
assert_that(c_flag.value).is_equal_to(0x10)
assert_that(multiplier.value).is_equal_to(1.0)
assert_that(offset.value).is_equal_to(0)
def test_gsfSetDefaultScaleFactor_success(gsf_test_data_03_09):
"""
Set estimated scale factors for a gsfSwathBathyPing structure.
"""
# Arrange
file_handle = c_int(0)
records = c_gsfRecords()
data_id = c_gsfDataID()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
# Set multibeam ping scale factors to be empty
records.mb_ping.scaleFactors = c_gsfScaleFactors()
return_value = gsfpy3_09.bindings.gsfSetDefaultScaleFactor(byref(records.mb_ping))
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
index = 0
assert_that(
records.mb_ping.scaleFactors.scaleTable[index].compressionFlag
).is_equal_to(0x00)
assert_that(
records.mb_ping.scaleFactors.scaleTable[index].multiplier
).is_equal_to(100.0)
assert_that(records.mb_ping.scaleFactors.scaleTable[index].offset).is_equal_to(
0
)
def test_gsfLoadDepthScaleFactorAutoOffset_success(gsf_test_data_03_09):
"""
Load scale factors for the depth subrecords of a gsfSwathBathyPing structure.
"""
# Arrange
file_handle = c_int(0)
records = c_gsfRecords()
data_id = c_gsfDataID()
# Act
return_value = gsfpy3_09.bindings.gsfOpen(
os.fsencode(str(gsf_test_data_03_09.path)),
FileMode.GSF_READONLY,
byref(file_handle),
)
assert_that(return_value).is_zero()
bytes_read = gsfpy3_09.bindings.gsfRead(
file_handle,
RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
byref(data_id),
byref(records),
)
assert_that(bytes_read).is_equal_to(132)
# Set multibeam ping scale factors to be empty
return_value = gsfpy3_09.bindings.gsfSetDefaultScaleFactor(byref(records.mb_ping))
assert_that(return_value).is_zero()
return_value = gsfpy3_09.bindings.gsfClose(file_handle)
assert_that(return_value).is_zero()
# Assert
with soft_assertions():
index = 0
assert_that(
records.mb_ping.scaleFactors.scaleTable[index].compressionFlag
).is_equal_to(0x00)
assert_that(
records.mb_ping.scaleFactors.scaleTable[index].multiplier
).is_equal_to(100.0)
assert_that(records.mb_ping.scaleFactors.scaleTable[index].offset).is_equal_to(
0
)
def test_gsfGetPositionDestination(gsf_test_data_03_09):
"""
Get a destination position (in degrees) given a starting position (in degrees)
and a set of offsets (in m).
"""
# Arrange
pos_start = c_GSF_POSITION()
pos_start.lon = c_double(10.0)
pos_start.lat = c_double(20.0)
pos_start.z = c_double(30.0)
offsets = c_GSF_POSITION_OFFSETS()
offsets.x = c_double(10000.0)
offsets.y = c_double(20000.0)
offsets.z = c_double(3.0)
heading = c_double(45.0)
dist_step = c_double(1)
# Act
position_destination = gsfpy3_09.bindings.gsfGetPositionDestination(
pos_start, offsets, heading, dist_step
)
# Assert
with soft_assertions():
assert_that(position_destination.contents.lon).is_close_to(10.20, 0.01)
assert_that(position_destination.contents.lat).is_close_to(19.94, 0.01)
assert_that(position_destination.contents.z).is_close_to(33.0, 0.000001)
def test_gsfGetPositionOffsets(gsf_test_data_03_09):
"""
Get offsets (in m) between given a starting position and a destination
position (measured in degrees).
"""
# Arrange
pos_start = c_GSF_POSITION()
pos_start.lon = c_double(10.0)
pos_start.lat = c_double(20.0)
pos_start.z = c_double(30.0)
pos_end = c_GSF_POSITION()
pos_end.lon = c_double(9.0)
pos_end.lat = c_double(22.0)
pos_end.z = c_double(40.0)
heading = c_double(90.0)
dist_step = c_double(1)
# Act
position_offsets = gsfpy3_09.bindings.gsfGetPositionOffsets(
pos_start, pos_end, heading, dist_step
)
# Assert
with soft_assertions():
assert_that(position_offsets.contents.x).is_close_to(103965, 0.5)
assert_that(position_offsets.contents.y).is_close_to(221434, 0.5)
assert_that(position_offsets.contents.z).is_close_to(20.0, 0.000001)
def test_gsfTestPingStatus(gsf_test_data_03_09):
"""
Test the status of a ping flag.
"""
# Arrange
mb_ping = c_gsfSwathBathyPing()
mb_ping.ping_flags = 0x0024
# Act
set_ping_status = gsfpy3_09.bindings.gsfTestPingStatus(
c_ushort(mb_ping.ping_flags), c_ushort(PingFlag.GSF_PING_USER_FLAG_05)
)
unset_ping_status = gsfpy3_09.bindings.gsfTestPingStatus(
c_ushort(mb_ping.ping_flags), c_ushort(PingFlag.GSF_PING_USER_FLAG_15)
)
# Assert
assert_that(set_ping_status).is_true()
assert_that(unset_ping_status).is_false()
def test_gsfSetPingStatus(gsf_test_data_03_09):
"""
Set the status of a ping flag.
"""
# Arrange
mb_ping = c_gsfSwathBathyPing()
mb_ping.ping_flags = 0x0024
# Act
new_ping_status = gsfpy3_09.bindings.gsfSetPingStatus(
c_ushort(mb_ping.ping_flags), c_ushort(PingFlag.GSF_PING_USER_FLAG_15)
)
# Assert
assert_that(new_ping_status.value).is_equal_to(0x8024)
def test_gsfClearPingStatus(gsf_test_data_03_09):
"""
Clear the status of a ping flag.
"""
# Arrange
mb_ping = c_gsfSwathBathyPing()
mb_ping.ping_flags = 0x0024
# Act
new_ping_status = gsfpy3_09.bindings.gsfClearPingStatus(
c_ushort(mb_ping.ping_flags), c_ushort(PingFlag.GSF_PING_USER_FLAG_02)
)
# Assert
assert_that(new_ping_status.value).is_equal_to(0x0020)
|
<reponame>Jumpscale/sandbox_linux
from js9 import j
from .MarkdownComponents import *
JSBASE = j.application.jsbase_get_class()
class MarkdownDocument(JSBASE):
def __init__(self, content="", path=""):
JSBASE.__init__(self)
if path != "":
content = j.sal.fs.fileGetContents(path)
self._content = content
self._tokens = ""
self._changed_tokens = False
self.items = []
self._parse()
self._dataCache = {}
def _findFancyHeaders(self):
if not self.content or self.content.strip() == "":
return
out = []
for line in self.content.split("\n"):
if line.startswith("===="):
out[-1] = "# %s" % out[-1]
continue
if line.startswith("-----"):
out[-1] = "## %s" % out[-1]
continue
out.append(line)
self._content = "\n".join(out)
def table_add(self):
"""
returns table which needs to be manipulated
"""
t = MDTable()
self.items.append(t)
return t
def header_add(self, level, title):
"""
"""
self.items.append(MDHeader(level, title))
def listitem_add(self, level, text):
"""
"""
self.items.append(MDListItem(level, text))
def comment_add(self, text):
"""
"""
self.items.append(MDComment(text))
def comment1line_add(self, text):
"""
"""
self.items.append(MDComment1Line(text))
def block_add(self, text):
"""
"""
self.items.append(MDBlock(text))
def code_add(self, text, lang):
"""
"""
self.items.append(MDCode(text, lang))
def data_add(self, ddict, name="", guid=""):
ddict = copy.copy(ddict)
self.items.append(MDData(ddict, name, guid))
def _parse(self):
self._findFancyHeaders()
state = ""
block = ""
prevListLevel = 0
curListLevel = 1
substate = ""
def addBlock(block):
if block.strip() != "":
self.block_add(block)
substate = ""
state = ""
return ""
if not self.content or self.content.strip() == '':
return
for line in self.content.split("\n"):
# HEADERS
if line.startswith("#"):
block = addBlock(block)
level = 0
line0 = line
while line0.startswith("#"):
level += 1
line0 = line0[1:]
title = line0.strip()
self.items.append(MDHeader(level, title))
continue
linestripped = line.strip()
# substate
if linestripped.startswith("<!--") and linestripped.endswith("-->"):
substate = linestripped[4:-3].strip()
self.addMDComment1Line(substate)
block = ""
state = ""
continue
if line.startswith("<!-"):
state = "COMMENT"
continue
# process all comment states
if state.startswith("COMMENT"):
if line.startswith("-->"):
state = ""
if state == "COMMENT":
self.items.append(MDComment(block))
block = ""
continue
block += "%s\n" % line
# LIST
if linestripped.startswith("-") or linestripped.startswith("*"):
if state == "":
block = addBlock(block)
state = "LIST"
curListLevel = 1
prevListLevel = 0
prevlevels = {0: 1}
if state == "LIST":
if not (linestripped.startswith("-") or linestripped.startswith("*")):
state
line0 = line
level = 0
while line0.startswith(" "):
level += 1
line0 = line0[1:]
# see how level goes up or down
if level in prevlevels:
curListLevel = prevlevels[level]
elif level > prevListLevel:
curListLevel += 1
prevlevels[level] = curListLevel
prevListLevel = level
self.items.append(MDListItem(
curListLevel, line.strip("* ")))
continue
else:
# get out of state state
if state == "LIST":
state = ""
if state == "TABLE" and not linestripped.startswith("|"):
state = ""
self.items.append(table)
table = None
cols = []
# TABLE
if state != "TABLE" and linestripped.startswith("|"):
state = "TABLE"
block = addBlock(block)
cols = [item.strip()
for item in line.split("|") if item.strip() != ""]
table = MDTable()
table.addHeader(cols)
continue
if state == "TABLE":
if linestripped.startswith("|") and linestripped.endswith("|") and line.find("---") != -1:
continue
cols = [item.strip() for item in line.strip().strip('|').split("|")]
table.addRow(cols)
continue
# CODE
if state == "" and linestripped.startswith("```") or linestripped.startswith("'''"):
block = addBlock(block)
state = "CODE"
lang = line.strip("'` ")
continue
if state == "CODE":
if linestripped.startswith("```") or linestripped.startswith("'''"):
state = ""
# from pudb import set_trace; set_trace()
if substate.startswith("data"):
tmp, name, guid = substate.split("|")
data = j.data.serializer.yaml.loads(str(block))
self.data_add(data, name, guid)
else:
self.items.append(MDCode(block, lang))
block = ""
else:
block += "%s\n" % line
continue
if linestripped != "":
block += "%s\n" % line
block = addBlock(block)
@property
def content(self):
return self._content
@property
def tokens(self):
if self._tokens == "":
bl = BlockLexer()
self._tokens = bl.parse(self._content)
return self._tokens
@tokens.setter
def tokens(self, val):
self._changed_tokens = True
self._tokens = val
def hashlist_get(self, ttype):
res = {}
for item in self.items:
if item.type == "data" and item.name == ttype:
res[item.guid] = item.hash
return res
def datacollection_get(self, ttype):
"""
ttype is name of the data block
"""
res = {}
for item in self.items:
if item.type == "data" and item.name == ttype:
res[item.guid] = item.ddict
key = "%s__%s" % (ttype, item.guid)
self._dataCache[key] = item
return res
def dataobj_get(self, ttype, guid):
"""
ttype is name for the block
guid is unique id, can be name or guid or int(id)
"""
key = "%s__%s" % (ttype, guid)
if key not in self._dataCache:
self.datacollection_get()
if key not in self._dataCache:
raise j.exceptions.Input(
"Cannot find object with type:%s guid:%s" % (ttype, guid))
return self._dataCache[key].ddict
def __repr__(self):
out = ""
prevtype = ""
for item in self.items:
if item.type not in ["list"]:
if prevtype == "list":
out += "\n"
out += str(item).strip() + "\n\n"
else:
out += str(item).rstrip() + "\n"
prevtype = item.type
return out
__str__ = __repr__
|
from __future__ import absolute_import, division, print_function, unicode_literals
import balanced
from braintree.test.nonces import Nonces
import mock
from gratipay.testing.billing import BillingHarness
from gratipay.models.exchange_route import ExchangeRoute
from gratipay.models.participant import Participant
class TestRoutes(BillingHarness):
def hit(self, username, action, network, address, expected=200):
r = self.client.POST('/~%s/routes/%s.json' % (username, action),
data=dict(network=network, address=address),
auth_as=username, raise_immediately=False)
assert r.code == expected
return r
def test_associate_and_delete_valid_card(self):
self.hit('roman', 'associate', 'braintree-cc', Nonces.Transactable)
customer = self.roman.get_braintree_account()
cards = customer.credit_cards
assert len(cards) == 1
assert self.roman.get_credit_card_error() == ''
self.hit('roman', 'delete', 'braintree-cc', cards[0].token)
customer = self.roman.get_braintree_account()
assert len(customer.credit_cards) == 0
roman = Participant.from_username('roman')
assert roman.get_credit_card_error() == 'invalidated'
assert roman.braintree_customer_id
def test_associate_invalid_card(self):
self.hit('roman', 'associate', 'braintree-cc', 'an-invalid-nonce', expected=400)
assert self.roman.get_credit_card_error() is None
def test_associate_and_delete_bank_account_valid(self):
bank_account = balanced.BankAccount( name='<NAME>'
, routing_number='321174851'
, account_number='9900000001'
, account_type='checking'
).save()
customer = self.david.get_balanced_account()
customer.merchant_status = 'underwritten'
with mock.patch.object(Participant, 'get_balanced_account') as gba:
gba.return_value = customer
self.hit('david', 'associate', 'balanced-ba', bank_account.href)
bank_accounts = customer.bank_accounts.all()
assert len(bank_accounts) == 1
assert bank_accounts[0].href == bank_account.href
assert self.david.get_bank_account_error() == ''
assert self.david.has_payout_route
self.hit('david', 'delete', 'balanced-ba', bank_account.href)
david = Participant.from_username('david')
route = ExchangeRoute.from_address(david, 'balanced-ba', bank_account.href)
assert route.error == david.get_bank_account_error() == 'invalidated'
assert david.balanced_customer_href
# Check that update_error doesn't update an invalidated route
route.update_error('some error')
assert route.error == david.get_bank_account_error() == 'invalidated'
assert not self.david.has_payout_route
@mock.patch.object(Participant, 'get_balanced_account')
def test_associate_bank_account_invalid(self, gba):
gba.return_value.merchant_status = 'underwritten'
self.hit('david', 'associate', 'balanced-ba', '/bank_accounts/BA123123123', expected=400)
assert self.david.get_bank_account_error() is None
assert not self.david.has_payout_route
@mock.patch.object(Participant, 'send_email')
def test_associate_paypal(self, mailer):
mailer.return_value = 1 # Email successfully sent
self.david.add_email('<EMAIL>')
self.db.run("UPDATE emails SET verified=true WHERE address='<EMAIL>'")
self.hit('david', 'associate', 'paypal', '<EMAIL>')
assert ExchangeRoute.from_network(self.david, 'paypal')
assert self.david.has_payout_route
def test_associate_paypal_invalid(self):
r = self.hit('david', 'associate', 'paypal', '<EMAIL>', expected=400)
assert not ExchangeRoute.from_network(self.david, 'paypal')
assert not self.david.has_payout_route
assert "Only verified email addresses allowed." in r.body
def test_associate_bitcoin(self):
addr = '17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j'
self.hit('david', 'associate', 'bitcoin', addr)
route = ExchangeRoute.from_network(self.david, 'bitcoin')
assert route.address == addr
assert route.error == ''
def test_associate_bitcoin_invalid(self):
self.hit('david', 'associate', 'bitcoin', '12345', expected=400)
assert not ExchangeRoute.from_network(self.david, 'bitcoin')
def test_bank_account_page(self):
expected = "add or change your bank account"
actual = self.client.GET('/~alice/routes/bank-account.html').body
assert expected in actual
def test_bank_account_page_auth(self):
self.make_participant('alice', claimed_time='now')
expected = '<em id="status">not connected</em>'
actual = self.client.GET('/~alice/routes/bank-account.html', auth_as='alice').body
assert expected in actual
def test_credit_card_page(self):
self.make_participant('alice', claimed_time='now')
expected = "add or change your credit card"
actual = self.client.GET('/~alice/routes/credit-card.html').body
assert expected in actual
def test_credit_card_page_shows_card_missing(self):
self.make_participant('alice', claimed_time='now')
expected = 'Your credit card is <em id="status">missing'
actual = self.client.GET('/~alice/routes/credit-card.html', auth_as='alice').body.decode('utf8')
assert expected in actual
def test_credit_card_page_loads_when_there_is_a_braintree_card(self):
expected = 'Your credit card is <em id="status">working'
actual = self.client.GET('/~obama/routes/credit-card.html', auth_as='obama').body.decode('utf8')
assert expected in actual
def test_credit_card_page_shows_details_for_braintree_cards(self):
response = self.client.GET('/~obama/routes/credit-card.html', auth_as='obama').body.decode('utf8')
assert self.bt_card.masked_number in response
def test_receipt_page_loads_for_braintree_cards(self):
ex_id = self.make_exchange(self.obama_route, 113, 30, self.obama)
url_receipt = '/~obama/receipts/{}.html'.format(ex_id)
actual = self.client.GET(url_receipt, auth_as='obama').body.decode('utf8')
assert self.bt_card.card_type in actual
# Remove once we've moved off balanced
def test_associate_balanced_card_should_fail(self):
card = balanced.Card(
number='4242424242424242',
expiration_year=2020,
expiration_month=12
).save()
customer = self.david.get_balanced_account()
self.hit('david', 'associate', 'balanced-cc', card.href, expected=400)
cards = customer.cards.all()
assert len(cards) == 0
def test_credit_card_page_loads_when_there_is_a_balanced_card(self):
expected = 'Your credit card is <em id="status">working'
actual = self.client.GET('/~janet/routes/credit-card.html', auth_as='janet').body.decode('utf8')
assert expected in actual
def test_credit_card_page_shows_details_for_balanced_cards(self):
response = self.client.GET('/~janet/routes/credit-card.html', auth_as='janet').body.decode('utf8')
assert self.card.number in response
def test_credit_card_page_shows_when_balanced_card_is_failing(self):
ExchangeRoute.from_network(self.janet, 'balanced-cc').update_error('Some error')
expected = 'Your credit card is <em id="status">failing'
actual = self.client.GET('/~janet/routes/credit-card.html', auth_as='janet').body.decode('utf8')
assert expected in actual
def test_receipt_page_loads_for_balanced_cards(self):
ex_id = self.make_exchange('balanced-cc', 113, 30, self.janet)
url_receipt = '/~janet/receipts/{}.html'.format(ex_id)
actual = self.client.GET(url_receipt, auth_as='janet').body.decode('utf8')
assert 'Visa' in actual
|
<filename>anasymod/plugins.py<gh_stars>10-100
import os
from anasymod.sources import Sources, VerilogHeader, VerilogSource, VHDLSource
from anasymod.defines import Define
from anasymod.enums import ConfigSections
from anasymod.base_config import BaseConfig
class Plugin():
def __init__(self, cfg_file, prj_root, build_root, name):
self.args = None
self._cfg_file = cfg_file
self._prj_root = prj_root
self._build_root = build_root
self._srccfg_path = os.path.join(self._prj_root, r"source.yaml")
self._name = name
self._defines = []
self.generator_sources = []
self._verilog_sources = []
""":type : List[VerilogSource]"""
self._verilog_headers = []
""":type : List[VerilogHeader]"""
self._vhdl_sources = []
""":type : List[VHDLSource]"""
# List of includes that need to be added to source files generated via ANASYMOD
self.cfg = Config(cfg_file=self._cfg_file)
self.include_statements = []
#### User Functions ####
def models(self):
"""
Runs source code generator.
"""
raise NotImplementedError()
def set_option(self, name, value=None):
func = getattr(self, name)
if callable(func):
if value is True or None:
func()
elif not value:
pass
else:
func(value)
else:
raise Exception(f'ERROR: Provided option:{name} is not supported for this generator.')
#### Utility Functions ####
def _add_source(self, source: Sources):
if isinstance(source, VerilogSource):
self._verilog_sources.append(source)
if isinstance(source, VerilogHeader):
self._verilog_headers.append(source)
if isinstance(source, VHDLSource):
self._vhdl_sources.append(source)
def _add_define(self, define: Define):
self._defines.append(define)
def _dump_defines(self):
return self._defines
def _dump_verilog_sources(self):
return self._verilog_sources
def _dump_verilog_headers(self):
return self._verilog_headers
def _dump_vhdl_sources(self):
return self._vhdl_sources
def _setup_sources(self):
"""
Add Source objects that are specific to MSDSL
"""
raise NotImplementedError()
def _setup_defines(self):
"""
Add Define objects that are specific to MSDSL
"""
raise NotImplementedError()
def _parse_args(self):
"""
Read command line arguments. This supports convenient usage from command shell e.g.:
python analysis.py -i filter --models --sim --view
"""
pass
def _return_args(self):
return self.args
def _set_generator_sources(self, generator_sources: list):
"""
Set, which functional models shall be generated via the msdsl plugin. This works by setting the class instance
attribute self.generator_sources.
:param generator_sources: List of source objects specific to the generator
"""
if any(isinstance(i, Sources) for i in generator_sources): # Make sure all elements in the list are of type Sources
[i.expand_paths() for i in generator_sources]
self.generator_sources = generator_sources
else:
raise Exception(f'ERROR: Format for argument generator_sources is incorrect, expected list, got:{type(generator_sources)}')
class Config(BaseConfig):
"""
Container to store all config attributes.
"""
def __init__(self, cfg_file):
super().__init__(cfg_file=cfg_file, section=ConfigSections.PLUGIN) |
# coding=utf-8
# Copyright (C) 2020-2021 PowerLZY.
# This file is part of Bold-Falcon - https://github.com/PowerLZY/Bold-Falcon
# See the file 'docs/LICENSE' for copying permission.
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import Dataset
class MalConv(nn.Module):
def __init__(self,input_length=2000000,window_size=500):
super(MalConv, self).__init__()
self.embed = nn.Embedding(257, 8, padding_idx=0)
self.conv_1 = nn.Conv1d(4, 128, window_size, stride=window_size, bias=True)
self.conv_2 = nn.Conv1d(4, 128, window_size, stride=window_size, bias=True)
self.BatchNorm1d = nn.BatchNorm1d(128)
self.pooling = nn.MaxPool1d(int(input_length/window_size))
self.fc_1 = nn.Linear(128,128)
self.fc_2 = nn.Linear(128,1)
#self.BatchNorm1d = nn.BatchNorm1d(128)
self.sigmoid = nn.Sigmoid()
#self.softmax = nn.Softmax()
def forward(self,x):
x = self.embed(x)
# Channel first
x = torch.transpose(x,-1,-2)
cnn_value = self.conv_1(x.narrow(-2, 0, 4))
cnn_value = self.BatchNorm1d(cnn_value)
gating_weight = self.sigmoid(self.conv_2(x.narrow(-2, 4, 4)))
x = cnn_value * gating_weight
x = self.pooling(x)
x = x.view(-1,128)
x = self.fc_1(x)
x = self.BatchNorm1d(x)
x = self.fc_2(x)
#x = self.sigmoid(x)
return x
class PreMalConv(nn.Module):
"""
Architecture implementation.
def __init__(self, pretrained_path=None, embedding_size=8, max_input_size=2 ** 20):
super(MalConv, self).__init__(embedding_size, max_input_size, 256, False)
self.embedding_1 = nn.Embedding(num_embeddings=257, embedding_dim=embedding_size)
self.conv1d_1 = nn.Conv1d(in_channels=embedding_size, out_channels=128, kernel_size=(500,), stride=(500,),
groups=1, bias=True)
self.conv1d_2 = nn.Conv1d(in_channels=embedding_size, out_channels=128, kernel_size=(500,), stride=(500,),
groups=1, bias=True)
self.dense_1 = nn.Linear(in_features=128, out_features=128, bias=True)
self.dense_2 = nn.Linear(in_features=128, out_features=1, bias=True)
"""
def __init__(self, input_length=2 ** 20, window_size=500):
super(PreMalConv, self).__init__()
self.embedding_1 = nn.Embedding(257, 8, padding_idx=0)
self.conv1d_1 = nn.Conv1d(8, 128, window_size, stride=window_size, bias=True)
self.conv1d_2 = nn.Conv1d(8, 128, window_size, stride=window_size, bias=True)
self.pooling = nn.MaxPool1d(int(input_length / window_size))
self.dense_1 = nn.Linear(128, 128)
self.dense_2 = nn.Linear(128, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.embedding_1(x)
# Channel first
x = torch.transpose(x, -1, -2)
cnn_value = self.conv1d_1(x)
cnn_value = torch.relu(cnn_value)
gating_weight = self.sigmoid(self.conv1d_2(x))
x = cnn_value * gating_weight
global_max_pooling1d_1 = F.max_pool1d(input=x, kernel_size=x.size()[2:])
global_max_pooling1d_1_flatten = global_max_pooling1d_1.view(global_max_pooling1d_1.size(0), -1)
x = torch.relu(self.dense_1(global_max_pooling1d_1_flatten))
dense_1_activation = torch.relu(x)
dense_2 = self.dense_2(x)
dense_2_activation = torch.sigmoid(dense_2)
return dense_2_activation
class ExeDataset(Dataset):
'''
Dataset preparation
'''
def __init__(self, fp_list, data_path, label_list = None, first_n_byte=2000000):
self.fp_list = fp_list
self.data_path = data_path
self.label_list = label_list
self.first_n_byte = first_n_byte
# ToDo: 自动载入数据
def __len__(self):
"""
返回数据集item数
"""
return len(self.fp_list)
def __getitem__(self, idx):
"""
返回一条训练数据,并将其转换成tensor
"""
try:
with open(self.data_path + self.fp_list[idx],'rb') as f:
tmp = [i+1 for i in f.read()[:self.first_n_byte]] # index 0 will be special padding index 每个值加一
tmp = tmp+[0]*(self.first_n_byte-len(tmp))
except:
with open(self.data_path + self.fp_list[idx].lower(),'rb') as f:
tmp = [i+1 for i in f.read()[:self.first_n_byte]]
tmp = tmp+[0]*(self.first_n_byte-len(tmp))
return np.array(tmp), np.array([self.label_list[idx]])
|
##############################
# Import necessary libraries #
##############################
import numpy as np
from scipy.optimize import fsolve
##################################
# Define various math functions. #
##################################
def norm(v):
return np.sqrt(np.dot(v,v))
def S(z):
return ( np.sqrt(z) - np.sin(np.sqrt(z)) ) / np.sqrt(z**3)
def C(z):
return ( 1 - np.cos(np.sqrt(z)) ) / z
######################################
# Define class for celestial bodies. #
######################################
# This works at the moment only for elliptical (generic) orbits. Fix this!
class celestial_body:
# This class assumes a reference coordinate system such that a large mass is situated at the origin. It might actually assume some more things.
####### Init #######
def __init__(self,mass,mu,semi_major_axis,eccentricity,inclination,longitude_ascending_node,argument_periapsis,true_anomaly_epoch):
# Initialization of class using classical orbital elements a, e, i, Omega, omega, nu_0
self.semi_major_axis = semi_major_axis # a
self.energy = - mu / ( 2.0 * self.semi_major_axis ) # E
self.eccentricity = eccentricity # e
if self.energy < 0:
if self.eccentricity == 0:
self.type = "circular"
else:
self.type = "elliptical"
elif self.energy == 0:
self.type = "parabolic"
else:
self.type = "hyperbolic"
self.inclination = inclination # i
if inclination == 0:
self.planar == True
else:
self.planar == False
if self.planar == False:
self.longitude_ascending_node = longitude_ascending_node # Omega
self.argument_periapsis = argument_periapsis # omega
else:
self.longitude_ascending_node = 0
self.argument_periapsis = 0
self.true_anomaly_epoch = true_anomaly_epoch # nu
self.mass = mass # m
self.parameter = semi_major_axis * (1 - eccentricity**2) # p
if ( 0 <= self.true_anomaly_epoch ) and ( self.true_anomaly_epoch <= np.pi):
self.eccentric_anomaly = np.arccos((self.eccentricity + np.cos(self.true_anomaly_epoch)) / (1 + self.eccentricity * np.cos(self.true_anomaly_epoch))) # E, at the moment the cases dont't cover everything.
else:
self.eccentric_anomaly = 2 * np.pi - np.arccos((self.eccentricity + np.cos(self.true_anomaly_epoch)) / (1 + self.eccentricity * np.cos(self.true_anomaly_epoch))) # E
self.mean_anomaly = self.eccentric_anomaly - self.eccentricity * np.sin(self.eccentric_anomaly) # M
self.mean_motion = np.sqrt(mu / self.semi_major_axis**3 ) # n
self.period = 2 * np.pi / np.sqrt(mu) * np.sqrt(self.semi_major_axis**3) # T
self.mu = mu # mu
self.X = 0 # X for universal formulation of time of flight
@classmethod
def from_position_velocity(self,mass,mu,position,velocity):
# Initialization of class using position and momentum
# For this purpose we need to calculate various intermediate objects. Should we save them for later? Is it more clever to just use position and momentum all the time?
h = np.cross(position,velocity) # Calculate angular momentum h
if h != [0,0,0]:
n = np.cross(np.array([0,0,1],float),h) # Calculate node vector
e = 1.0 / mu * ((np.dot(velocity,velocity) - mu / norm(position)) * position - np.dot(position,velocity) * velocity) # Calculate eccentricity vector pointing in direction of perihelion
p = np.dot(h,h) / mu
# Is it better to just save the cosine of the angles?
semi_major_axis = p / (1-np.dot(e,e))
eccentricity = norm(e)
inclination = np.arccos(h[2] / norm(h))
if position[1] >= 0:
longitude_ascending_node = np.arccos(n[0] / norm(n))
else:
longitude_ascending_node = 2 * np.pi - np.arccos(n[0] / norm(n))
if e[2] >= 0:
argument_periapsis = np.arccos(np.dot(n,e) / (norm(n) * norm(e)))
else:
argument_periapsis = 2 * np.pi - np.arccos(np.dot(n,e) / (norm(n) * norm(e)))
if np.dot(position,velocity) >= 0:
true_anomaly_epoch = np.arccos(np.dot(e,position) / (norm(e) * norm(position)))
else:
true_anomaly_epoch = 2 * np.pi - np.arccos(np.dot(e,position) / (norm(e) * norm(position)))
body = celestial_body(mass,mu,semi_major_axis,eccentricity,inclination,longitude_ascending_node,argument_periapsis,true_anomaly_epoch)
return body
else:
return celestial_object.initialize_collision_orbit(mass,mu,position,velocity)
@classmethod
def initialize_collision_orbit(self,mass,mu,position,velocity):
pass
####### Export #######
def export_position_velocity(self):
# Exports position and velocity of celestial body. How should time dependence be incorparated? Should it be a parameter for this function?
r = self.parameter / ( 1 + self.eccentricity * np.cos(self.true_anomaly_epoch))
# The perifocal coordinate system uses coordinate axes P, Q, W in this order, where P points in the direction of the periapsis and Q is perpendicular in positive direction in the plane of the orbit.
position_perifocal_system = np.array([r * np.cos(self.true_anomaly_epoch),r * np.sin(self.true_anomaly_epoch),0],float)
velocity_perifocal_system = np.sqrt(self.mu / self.parameter) * np.array([-np.sin(self.true_anomaly_epoch),self.eccentricity + np.cos(self.true_anomaly_epoch),0],float)
# Calculate the rotation matrix from perifocal to fixed frame. Bate says, one should avoid this technique.
rotation_matrix = np.array([[np.cos(self.longitude_ascending_node) * np.cos(self.argument_periapsis) - np.sin(self.longitude_ascending_node) * np.sin(self.argument_periapsis) * np.cos(self.inclination) , - np.cos(self.longitude_ascending_node) * np.sin(self.argument_periapsis) - np.sin(self.longitude_ascending_node) * np.cos(self.argument_periapsis) * np.cos(self.inclination) , np.sin(self.longitude_ascending_node) * np.sin(self.inclination)],\
[np.sin(self.longitude_ascending_node) * np.cos(self.argument_periapsis) + np.cos(self.longitude_ascending_node) * np.sin(self.argument_periapsis) * np.cos(self.inclination) , - np.sin(self.longitude_ascending_node) * np.sin(self.argument_periapsis) + np.cos(self.longitude_ascending_node) * np.cos(self.argument_periapsis) * np.cos(self.inclination) , - np.cos(self.longitude_ascending_node) * np.sin(self.inclination)],\
[ np.sin(self.argument_periapsis) * np.sin(self.inclination) , np.cos(self.argument_periapsis) * np.sin(self.inclination) , np.cos(self.inclination)]\
],float)
position = np.dot(rotation_matrix,position_perifocal_system)
velocity = np.dot(rotation_matrix,velocity_perifocal_system)
return position, velocity
def export_orbit(self,number_points):
# Returns a list of three dimensional coordinates for the orbit.
position = np.zeros( (number_points,3) )
interval = 2 * np.pi / number_points
for i in range(number_points):
position[i,:] = self.calculate_advance_in_true_anomaly(i * interval)[0]
return np.vstack( (position,position[0,:]) )
###### Advance along orbit #######
def advance_in_time(self,delta_t):
# This method advances the object on its course by delta t in time. This means that it needs to translate the time difference into changes in the true anomaly at epoch and then add this number to the existing value.
# delta_t should be small enough such that the body does not evolve more than one period. Is this necessary?
# Update mean anomaly. Ignore full rotations.
new_mean_anomaly = self.mean_motion * delta_t + self.mean_anomaly
# Solve E-e*sin(E)=M numerically
new_eccentric_anomaly = fsolve(lambda E : E - self.eccentricity * np.sin(E) -new_mean_anomaly,new_mean_anomaly)
# Calculate new true anomaly at epoch
if new_eccentric_anomaly <= np.pi:
new_true_anomaly_epoch = np.arccos( ( np.cos(new_eccentric_anomaly) - self.eccentricity ) / ( 1 - self.eccentricity * np.cos(new_eccentric_anomaly)))
else:
new_true_anomaly_epoch = 2 * np.pi - np.arccos( ( np.cos(new_eccentric_anomaly) - self.eccentricity ) / ( 1 - self.eccentricity * np.cos(new_eccentric_anomaly)))
# Update values of true anomaly at epoch and eccentric anomaly and mean anomaly
self.true_anomaly_epoch = new_true_anomaly_epoch
self.mean_anomaly = new_mean_anomaly
self.eccentric_anomaly = new_eccentric_anomaly
def t_in_dep_of_X(self, X):
r_0, v_0 = self.export_postion_velocity()
return 1 / np.sqrt(self.mu) * ( np.dot(r_0,v_0) /np.sqrt(self.mu) * X**2 * C(X) + ( 1 - norm(r_0) / self.semi_major_axis ) * X**3 * S(X) + norm(r_0) * X )
def advance_in_time_universal(self,delta_t):
# This method advances the object on its course by delta t in time using the universal time of fligt formulation. This means it should be usable for all kinds of orbits.
# Solve for new X
new_X = fsolve(lambda X : self.t_in_dep_of_X(X) - delta_t,delta_t)
def advance_in_true_anomaly(self,delta_nu):
# This method increases the true anomaly by a given input. It can be used to find equi-distant-angle points on the orbit for visualization purposes. It also updates eccentric anomaly and mean anomaly.
self.true_anomaly_epoch = self.true_anomaly_epoch + delta_nu
if self.true_anomaly_epoch <= np.pi:
self.eccentric_anomaly = np.arccos( ( np.cos(self.true_anomaly_epoch) + self.eccentricity ) / ( 1 + self.eccentricity * np.cos(self.true_anomaly_epoch)))
else:
self.eccentric_anomaly = 2 * np.pi - np.arccos( ( np.cos(self.true_anomaly_epoch) + self.eccentricity ) / ( 1 + self.eccentricity * np.cos(self.true_anomaly_epoch)))
self.mean_anomaly = self.eccentric_anomaly - self.eccentricity * np.sin( self.eccentric_anomaly )
def calculate_advance_in_true_anomaly(self,delta_nu):
# This method advances the object on its course by delta nu in true anomaly and returns the new position. It is useful for calculating points on the orbit without actually advancing the object itself.
new_true_anomaly_epoch = self.true_anomaly_epoch + delta_nu
r = self.parameter / ( 1 + self.eccentricity * np.cos(new_true_anomaly_epoch))
# The perifocal coordinate system uses coordinate axes P, Q, W in this order, where P points in the direction of the periapsis and Q is perpendicular in positive direction in the plane of the orbit.
position_perifocal_system = np.array([r * np.cos(new_true_anomaly_epoch),r * np.sin(new_true_anomaly_epoch),0],float)
velocity_perifocal_system = np.sqrt(self.mu / self.parameter) * np.array([-np.sin(new_true_anomaly_epoch),self.eccentricity + np.cos(new_true_anomaly_epoch),0],float)
# Calculate the rotation matrix from perifocal to fixed frame. Bate says, one should avoid this technique.
rotation_matrix = np.array([[np.cos(self.longitude_ascending_node) * np.cos(self.argument_periapsis) - np.sin(self.longitude_ascending_node) * np.sin(self.argument_periapsis) * np.cos(self.inclination) , - np.cos(self.longitude_ascending_node) * np.sin(self.argument_periapsis) - np.sin(self.longitude_ascending_node) * np.cos(self.argument_periapsis) * np.cos(self.inclination) , np.sin(self.longitude_ascending_node) * np.sin(self.inclination)],\
[np.sin(self.longitude_ascending_node) * np.cos(self.argument_periapsis) + np.cos(self.longitude_ascending_node) * np.sin(self.argument_periapsis) * np.cos(self.inclination) , - np.sin(self.longitude_ascending_node) * np.sin(self.argument_periapsis) + np.cos(self.longitude_ascending_node) * np.cos(self.argument_periapsis) * np.cos(self.inclination) , - np.cos(self.longitude_ascending_node) * np.sin(self.inclination)],\
[ np.sin(self.argument_periapsis) * np.sin(self.inclination) , np.cos(self.argument_periapsis) * np.sin(self.inclination) , np.cos(self.inclination)]\
],float)
position = np.dot(rotation_matrix,position_perifocal_system)
velocity = np.dot(rotation_matrix,velocity_perifocal_system)
return position, velocity
|
<reponame>eigenphi/gcommon
# -*- coding: utf-8 -*-
# created: 2021-07-29
# creator: <EMAIL>
import collections
import logging
from copy import copy
from datetime import datetime
from types import TracebackType
from typing import (
Any,
AnyStr,
AsyncContextManager,
AsyncGenerator,
Awaitable,
Callable,
Dict,
Generator,
List,
Optional,
Tuple,
Type,
TYPE_CHECKING,
Union,
)
from aiokafka import AIOKafkaConsumer, AIOKafkaProducer
from kafka.errors import KafkaError, KafkaConnectionError
from gcommon.aio import gasync
from gcommon.utils import gtime, gerrors
from gcommon.utils.gjsonobj import JsonObject
from gcommon.utils.gobject import ObjectWithLogger
logger = logging.getLogger("kafka")
class KafkaConfig(object):
API_VERSION = (0, 10)
bootstrap_servers = ""
group_id = __file__
topic = ""
topics = []
security_protocol = "PLAINTEXT"
sasl_mechanism = "PLAIN"
sasl_plain_username = ""
sasl_plain_password = ""
# offset_reset = "earliest"
offset_reset = "latest"
auto_commit = False
def clone(self):
return copy(self)
@staticmethod
def create(config: JsonObject):
self = KafkaConfig()
self.bootstrap_servers = config.get('servers')
self.group_id = config.get('consumer_group')
self.security_protocol = config.get('security_protocol')
self.sasl_mechanism = config.get('sasl_mechanism')
if config.offset:
self.offset_reset = config.offset
if config.enable_dynamic_group:
# 动态组,每次变更组名
self.group_id = self.group_id + f"-{int(gtime.Timestamp.seconds())}"
self.topics = config.get('topics')
return self
KafkaConsumerCallback = Callable[[str, str, datetime, JsonObject], Any]
class KafkaConsumer(object):
"""
callback -> KafkaConsumerCallback(topic, event_id, event_time, content)
"""
Message_Content_Is_Json = True
def __init__(self, kafka_config: KafkaConfig, callback: KafkaConsumerCallback = None):
self.config = kafka_config
if callback:
self._on_kafka_message = callback
async def consume_forever(self):
"""从制定 topic 中消费数据"""
topics = self.config.topics or [self.config.topic]
consumer = AIOKafkaConsumer(
*topics,
bootstrap_servers=self.config.bootstrap_servers,
group_id=self.config.group_id,
auto_offset_reset=self.config.offset_reset,
security_protocol=self.config.security_protocol,
sasl_mechanism=self.config.sasl_mechanism,
)
# Get cluster layout and join group
logger.debug("start kafka consumer: %s", self.config.bootstrap_servers)
try:
await consumer.start()
except KafkaError as kafka_error:
logger.critical("cannot connect to kafka server: %s, error: %s",
self.config.bootstrap_servers, kafka_error)
raise
try:
logger.debug("consume messages")
async for message in consumer:
try:
await self._process_kafka_message(message)
except:
logger.error("failed to process message: %s", gerrors.format_exception_stack())
await consumer.commit()
except KafkaError as kafka_error:
logger.critical("kafka consumer error: %s, error: %s",
self.config.bootstrap_servers, kafka_error)
raise
except:
logger.critical("kafka server error: %s", self.config.bootstrap_servers)
finally:
# Will leave consumer group; perform autocommit if enabled.
await consumer.stop()
async def _process_kafka_message(self, message):
logger.debug("message received, topic=%s, partition=%s, offset=%s, timestamp=%s",
message.topic, message.partition, message.offset, message.timestamp)
event_id = f"{message.topic}-{message.partition}-{message.offset}"
event_time = gtime.timestamp_to_date(int(message.timestamp / 1000))
content = message.value.decode("utf-8")
if self.Message_Content_Is_Json:
content = JsonObject.loads(content)
await gasync.maybe_async(self._on_kafka_message, message.topic,
event_id, event_time, content)
class KafkaProducer(object):
def __init__(self, kafka_config: KafkaConfig):
self.config = kafka_config
self.started = False
self.producer = AIOKafkaProducer(
bootstrap_servers=self.config.bootstrap_servers,
security_protocol=self.config.security_protocol,
sasl_mechanism=self.config.sasl_mechanism,
)
async def init(self):
# Get cluster layout and initial topic/partition leadership information
await self.producer.start()
self.started = True
async def send_json(self, topic, message: JsonObject, key=None):
# Produce message
assert self.started
value = message.dumps(ensure_ascii=False).encode('utf-8')
await self.producer.send_and_wait(topic, value=value, key=key)
async def stop(self):
# Wait for all pending messages to be delivered or expire.
if self.started:
await self.producer.stop()
self.started = False
|
# -*- coding: utf-8 -*-
"""
Created on Tue May 25 14:29:04 2021
@author: alankar
"""
import numpy as np
import matplotlib.pyplot as plt
import h5py
from operator import itemgetter
from decimal import Decimal
def fexp(number):
(sign, digits, exponent) = Decimal(number).as_tuple()
return len(digits) + exponent - 1
def fman(number):
return Decimal(number).scaleb(-fexp(number)).normalize()
Msun = 2e33 #g
yr = 365*24*60**2 #s
hdf = h5py.File('../data-gasandcloud.h5', 'r')
cl_r = np.array(hdf['cloud_size'])
hdf.close()
fig = plt.figure(figsize=(13,15))
#0 --> proxy for floating cutoff
cutoffs = [0, 5, 20] #, 20, 50, 100, 200, 300, 499]
size_sel_min, size_sel_max = np.min(cl_r), np.max(cl_r) #1.0, 1.5 #kpc
floating = False
if 0 in cutoffs: floating = True
Edot_allcl, T_plot_allcl = [], []
showit = [5, 40] #show all cloud total DEM
for cutoff in cutoffs:
emm = None
if cutoff!=0: emm = np.load('./diff-emm_all-cloud_%03dkpc.npy'%cutoff)
else: emm = np.load('./diff-emm_all-cloud_floating.npy')
#Temperature is in log scale
Temperature, Edot = [], [] #(cloud_no, Temperature) and (cloud_no, Edot)
#Cloud selection based on cloud size
for i,radius in enumerate(cl_r):
if (radius>=size_sel_min and radius<=size_sel_max):
Temperature.append(emm[i,:,0]) #(cloud_no, Temperature, Edot)
Edot.append(emm[i,:,1])
Temperature = np.array(Temperature).flatten()
select = 3.8 #selection based on gas temperature
cut = Temperature>=select
Temperature = Temperature[cut]
Edot = np.array(Edot).flatten()[cut]
#The binning of Edot in Temperature bins
#require temperature arranged in ascending order
sorter = sorted(zip(Temperature,Edot), key=itemgetter(0))
Temperature, Edot = zip(*sorter)
Temperature, Edot = np.array(Temperature), np.array(Edot)
print('Sort completed!')
Tstart, Tstop, Npts = np.min(Temperature), np.max(Temperature), 100
T_vals = np.linspace(Tstart,Tstop,Npts+1)
dT = T_vals[1] - T_vals[0]
Edot_vals, Edot_16p, Edot_84p, T_plot = [], [], [], []
tmp, T_curr = [], Tstart+dT
for i in range(Temperature.shape[0]):
if Temperature[i]<=T_curr:
tmp.append(Edot[i])
else:
T_curr += dT
tmp = np.array(tmp)
tmp = tmp[np.isfinite(np.log10(tmp))] #no heating terms
if len(tmp) == 0:
tmp = []
continue
Edot_vals.append(np.percentile(tmp,50))
Edot_16p.append(np.percentile(tmp,16))
Edot_84p.append(np.percentile(tmp,84))
if floating or (cutoff in showit):
Edot_allcl.append(np.sum(tmp))
T_plot_allcl.append(T_curr-1.5*dT)
T_plot.append(T_curr-1.5*dT)
tmp = []
T_plot, Edot_vals, Edot_16p, Edot_84p = np.array(T_plot), np.array(Edot_vals), np.array(Edot_16p), np.array(Edot_84p)
if floating or (cutoff in showit):
T_plot_allcl, Edot_allcl = np.array(T_plot_allcl), np.array(Edot_allcl)
if floating: floating = False
if cutoff == 5:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='tab:cyan',
label=r'Median cloud (%d kpc)'%cutoff)
#plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='tab:blue')
elif cutoff == 10:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='tab:green',
label=r'Median cloud (%d kpc)'%cutoff)
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='tab:green')
elif cutoff == 40:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='tab:olive',
label=r'Median cloud (%d kpc)'%cutoff)
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='tab:olive')
elif cutoff == 100:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='yellow',
label=r'Median cloud (%d kpc)'%cutoff)
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='yellow')
elif cutoff == 20:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='tab:purple',
label=r'Median cloud (%d kpc)'%cutoff)
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='tab:purple')
#plt.semilogy(T_plot_allcl,Edot_allcl,linewidth=8, color='tab:purple', linestyle='-.',
# label=r'All clouds (%d kpc)'%cutoff)
elif cutoff == 200:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='orange',
label=r'Median cloud (%d kpc)'%cutoff)
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='orange')
elif cutoff == 300:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='tab:brown',
label=r'Median cloud (%d kpc)'%cutoff)
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='tab:brown')
elif cutoff == 1200:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='tab:gray',
label=r'Median cloud (%d kpc)'%(cutoff+1))
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='tab:gray')
plt.semilogy(T_plot_allcl,Edot_allcl,linewidth=5, color='tab:gray', linestyle='-.',
label=r'All clouds (%d kpc)'%cutoff)
else:
plt.semilogy(T_plot,Edot_vals,linewidth=5, color='tab:blue',
label=r'Median cloud ($\rm 3 R_{cloud}$)')
plt.fill_between(T_plot, Edot_16p, Edot_84p, alpha=0.5, color='tab:blue')
#plt.semilogy(T_plot_allcl,Edot_allcl,linewidth=5, color='tab:blue', linestyle=':',
# label=r'All clouds ($\rm 3 R_{cloud}$)')
T_plot_allcl, Edot_allcl = [], []
#Analytic ODE prediction
data = np.loadtxt('../bernoulli-model(rTBeMdot).txt')
distance, Temperature, Be, Mdot = [data[:,i] for i in range(data.shape[1])]
diff_emm_analytic = np.gradient(Be, Temperature)*Mdot*Temperature*np.log(10)
Mdot = np.average(Mdot)/(Msun/yr)
plt.semilogy(np.log10(Temperature), diff_emm_analytic, color='chocolate', linestyle='--',linewidth=5,
label=r' $ \dot{\rm M}_{\rm cool} \rm = %.1f \times 10^{%d}\ M_\odot yr^{-1}$'%(fman(Mdot),fexp(Mdot))
#label=r'Steady cooling flow model'+'\n'+r'($ \dot{\rm M} \rm = %.1f \times 10^{%d}\ M_\odot yr^{-1}$)'%(fman(Mdot),fexp(Mdot)),
)
scale = 8e2
diff_emm_analytic *= scale
Mdot *= scale
plt.semilogy(np.log10(Temperature), diff_emm_analytic, color='firebrick', linestyle='--',linewidth=5,
label=r' $ \dot{\rm M}_{\rm cool} \rm = %.1f \times 10^{%d}\ M_\odot yr^{-1}$'%(fman(Mdot),fexp(Mdot))
#label=r'$\times %d$ Steady cooling flow model'%scale+'\n'+r'($ \dot{\rm M} \rm = %.1f \times 10^{%d}\ M_\odot yr^{-1}$)'%(fman(Mdot),fexp(Mdot)),
)
hdf = h5py.File('../data-gasandcloud.h5', 'r')
SFR = np.array(hdf['SFR'])
#exclude ISM --> SFR == 0
condition = SFR==0
Temperature = np.log10(np.array(hdf['temperature']))[condition]
nH = np.array(hdf['nH'])[condition]
vol = np.array(hdf['volume'])[condition]
Edot = -(np.array(hdf['LAMBDA'])[condition])*nH**2*vol
density = np.array(hdf['density'])[condition]
hdf.close()
#DEM all gas
scale = 1#e7
#Generate DEM data
hist_data, x_edges = np.histogram(Temperature, bins=100, weights=Edot)
dT = x_edges[1]-x_edges[0]
Temperature_bin = x_edges[1:]-dT/2
diff_emm = hist_data/dT
plt.semilogy(Temperature_bin,diff_emm/scale,linewidth=5, color='black', zorder=3,
label=r'All halo gas')
data_nocl = np.load('diff-emm-isolated.npy')
plt.semilogy(data_nocl[:,0], data_nocl[:,1], color='tab:gray', linewidth=5,
label=r'Non-cloud gas')
'''
data_onlycl = np.load('diff-emm-onlycl.npy')
plt.semilogy(data_onlycl[:,0], data_onlycl[:,1], color='tab:green', linewidth=5,
label=r'Cloud gas')
'''
plt.ylabel(r'$\rm \dfrac{d\dot{E}_{cool} [erg\ s^{-1}]}{d log_{10}( T [K])} $',size=28)
plt.xlabel(r'$\rm \log_{10}(T[K])$',size=28)
plt.tick_params(axis='both', which='major', labelsize=24, direction="out", pad=5)
plt.tick_params(axis='both', which='minor', labelsize=24, direction="out", pad=5)
plt.grid()
plt.ylim(ymin=10**34.2)#, ymax=1e40)
plt.xlim(xmin=np.min(Temperature_bin)-0.05, xmax=8.2)
plt.legend(loc='lower right', prop={'size': 22},framealpha=0.3, bbox_to_anchor=(0.88, 0))
fig.tight_layout()
plt.savefig('./diff-emm-cuts.png', transparent=True, bbox_inches='tight')
plt.show()
plt.close(fig)
#------------------Other useful diagonistics-------------------------------
fig, ax1 = plt.subplots(figsize=(13,10))
color = 'tab:red'
hist_data, x_edges = np.histogram(Temperature, bins=100, weights=vol, density=True)
dT = x_edges[1]-x_edges[0]
Temperature_bin = x_edges[1:]-dT/2
vol_temp = hist_data#/dT
ax1.semilogy(Temperature_bin,vol_temp, linewidth=5, color=color) #,
#label=r'Volume weighted')
ax1.set_ylabel(r'$\rm \dfrac{dV}{d log_{10}( T [K])} $',size=28, color=color)
ax1.tick_params(axis='y', which='major', labelsize=24, direction="out", pad=5, labelcolor=color)
ax1.tick_params(axis='y', which='minor', labelsize=24, direction="out", pad=5, labelcolor=color)
color = 'tab:blue'
ax2 = ax1.twinx()
hist_data, x_edges = np.histogram(Temperature, bins=100, weights=vol*density, density=True)
dT = x_edges[1]-x_edges[0]
Temperature_bin = x_edges[1:]-dT/2
mass_temp = hist_data#/dT
ax2.semilogy(Temperature_bin,mass_temp, linewidth=5, color=color) #,
#label=r'Mass weighted')
ax2.set_ylabel(r'$\rm \dfrac{dM}{d log_{10}( T [K])} $',size=28, color=color)
ax2.tick_params(axis='y', which='major', labelsize=24, direction="out", pad=5, labelcolor=color)
ax2.tick_params(axis='y', which='minor', labelsize=24, direction="out", pad=5, labelcolor=color)
hist_data, x_edges = np.histogram(Temperature, bins=100, weights=Edot, density=True)
dT = x_edges[1]-x_edges[0]
Temperature_bin = x_edges[1:]-dT/2
diff_emm = hist_data#/dT
plt.semilogy(Temperature_bin,diff_emm,linewidth=5, color='black', linestyle='-.',
label=r'$\rm \dfrac{d\dot{E}_{cool} [erg\ s^{-1}]}{d log_{10}( T [K])} $')
ax1.set_xlabel(r'$\rm \log_{10}(T[K])$',size=28)
ax1.grid()
ax1.set_xlim(xmin=np.min(Temperature_bin)-0.05, xmax=8.2)
ax1.set_ylim(ymin=1e-6, ymax=10**0.5)
ax2.set_ylim(ymin=1e-6, ymax=10**0.5)
ax1.tick_params(axis='x', which='major', labelsize=24, direction="out", pad=5, labelcolor='black')
ax1.tick_params(axis='x', which='minor', labelsize=24, direction="out", pad=5, labelcolor='black')
plt.legend(loc='lower left', prop={'size': 24},framealpha=0.3, bbox_to_anchor=(0.1, 0))
plt.savefig('./diff-emm-comparepdfs.png', transparent=True, bbox_inches='tight')
fig.tight_layout()
plt.show()
plt.close(fig)
individual = False
if individual:
fig = plt.figure(figsize=(13,10))
emm = np.load('./diff-emm_all-cloud_floating.npy')
for i in range (emm.shape[0]):
plt.semilogy(emm[i,:,0], emm[i,:,1],linewidth=2)
plt.ylabel(r'$\rm \dfrac{d\dot{E}_{cool} [erg\ s^{-1}]}{d log_{10}( T [K])} $',size=28)
plt.xlabel(r'$\rm \log_{10}(T[K])$',size=28)
plt.tick_params(axis='both', which='major', labelsize=24, direction="out", pad=5)
plt.tick_params(axis='both', which='minor', labelsize=24, direction="out", pad=5)
plt.grid()
plt.ylim(ymin=10**33.8, ymax=10**45.3)
plt.xlim(xmin=3.8, xmax=8.2)
plt.show()
plt.close(fig)
|
import inspect
from operator import methodcaller
from typing import (
TYPE_CHECKING,
Type,
Mapping,
Tuple,
Optional,
Set,
Dict,
Any,
)
from typic.checks import ismappingtype, isiterabletype, isliteral
from typic.compat import lru_cache
from typic.gen import Block, Keyword, ParameterKind
from typic.util import (
cached_type_hints,
cached_simple_attributes,
safe_get_params,
get_unique_name,
get_defname,
)
if TYPE_CHECKING:
from .common import Annotation, TranslatorT, SerdeProtocol, FieldIteratorT
from .resolver import Resolver
_itemscaller = methodcaller("items")
_valuescaller = methodcaller("values")
_iter = iter
class TranslatorTypeError(TypeError):
...
class TranslatorValueError(ValueError):
...
class TranslatorFactory:
"""Translation protocol factory for higher-order objects.
Notes
-----
For lower-order objects this will be functionally the same as a serializer.
"""
KWD_KINDS = frozenset(
{inspect.Parameter.KEYWORD_ONLY, inspect.Parameter.VAR_KEYWORD}
)
POS_KINDS = frozenset(
{inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.VAR_POSITIONAL}
)
VAR_KINDS = frozenset(
{inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD}
)
def __init__(self, resolver: "Resolver"):
self.resolver = resolver
def sig_is_undef(self, params: Mapping[str, inspect.Parameter]) -> bool:
return (not params) or {x.kind for x in params.values()}.issubset(
self.VAR_KINDS
)
def kw_only(self, params: Mapping[str, inspect.Parameter]) -> bool:
return not any(x.kind in self.POS_KINDS for x in params.values())
def pos_only(self, params: Mapping[str, inspect.Parameter]) -> bool:
return not any(x.kind in self.KWD_KINDS for x in params.values())
@staticmethod
def required_fields(params: Mapping[str, inspect.Parameter]) -> Set[str]:
return {x for x, y in params.items() if y.default is y.empty}
@staticmethod
def _fields_from_hints(
kind: ParameterKind,
hints: Mapping[str, Type],
) -> Mapping[str, inspect.Parameter]:
return {x: inspect.Parameter(x, kind, annotation=y) for x, y in hints.items()}
@staticmethod
def _fields_from_attrs(kind: ParameterKind, attrs: Tuple[str, ...]):
return {x: inspect.Parameter(x, kind) for x in attrs}
@lru_cache(maxsize=None)
def get_fields(
self, type: Type, as_source: bool = False
) -> Optional[Mapping[str, inspect.Parameter]]:
"""Get the fields for the given type.
Notes
-----
We want this to be the type's signature, we really do. But if for some reason we
can't make that happen, we fallback to a few known, semi-reliable methods for
making this happen.
"""
# Try first with the signature of the target if this is the target type
params = safe_get_params(type)
undefined = self.sig_is_undef(params)
if not as_source and not undefined:
return params
# Now we start building a fake signature
k: ParameterKind = inspect.Parameter.POSITIONAL_OR_KEYWORD
# **kwargs
if self.kw_only(params):
k = inspect.Parameter.KEYWORD_ONLY
# *args
elif self.pos_only(params):
k = inspect.Parameter.POSITIONAL_ONLY
# Fetch any type hints and try to use those.
hints = cached_type_hints(type)
if hints:
return self._fields_from_hints(k, hints)
# Fallback to the target object's defined attributes
# This will basically work for ORM models, Pydantic models...
# Anything that defines the instance using the class body.
attrs = cached_simple_attributes(type)
if attrs:
return self._fields_from_attrs(k, attrs)
# Can't be done.
return None if undefined else params
@lru_cache(maxsize=None)
def iterator(self, type: Type, values: bool = False) -> "FieldIteratorT":
"""Get an iterator function for a given type, if possible."""
if ismappingtype(type):
iter = _valuescaller if values else _itemscaller
return iter
if isiterabletype(type):
return _iter
fields = self.get_fields(type, as_source=True) or {}
if fields:
func_name = get_defname("iterator", (type, values))
oname = "o"
ctx: dict = {}
with Block(ctx) as main:
with main.f(func_name, Block.p(oname)) as func:
if values:
for f in fields:
func.l(f"{Keyword.YLD} {oname}.{f}")
else:
for f in fields:
func.l(f"{Keyword.YLD} {f!r}, {oname}.{f}")
return main.compile(name=func_name, ns=ctx)
raise TranslatorTypeError(
f"Cannot get iterator for type {type!r}, unable to determine fields."
) from None
@staticmethod
def _get_name(source: Type, target: Type) -> str:
return get_defname("translator", (source, target))
@staticmethod
def _iter_field_assigns(
fields: Mapping[str, inspect.Parameter],
oname: str,
protos: Mapping[str, "SerdeProtocol"],
ctx: Dict[str, Any],
):
for f, p in fields.items():
fset = f"{oname}.{f}"
if f in protos:
deser_name = f"{f}_deser"
proto = protos[f]
ctx[deser_name] = proto.transmute
fset = f"{deser_name}({fset})"
if p.kind != p.POSITIONAL_ONLY:
fset = f"{f}={fset}"
yield fset
@lru_cache(maxsize=None)
def _compile_translator(self, source: Type, target: Type) -> "TranslatorT":
if isliteral(target):
raise TranslatorTypeError(
f"Cannot translate to literal type: {target!r}. "
) from None
if isliteral(source):
raise TranslatorTypeError(
f"Cannot translate from literal type: {source!r}. "
) from None
# Get the target fields for translation.
target_fields = self.get_fields(target)
if target_fields is None:
raise TranslatorTypeError(
f"Cannot translate to type {target!r}. "
f"Unable to determine target fields."
) from None
# Ensure that the target fields are a subset of the source fields.
# We treat the target fields as the parameters for the target,
# so this must be true.
fields = self.get_fields(source, as_source=True) or {}
fields_to_pass = {x: fields[x] for x in fields.keys() & target_fields.keys()}
required = self.required_fields(target_fields)
if not required.issubset(fields_to_pass.keys()):
diff = (*(required - fields.keys()),)
raise TranslatorValueError(
f"{source!r} can't be translated to {target!r}. "
f"Source is missing required fields: {diff}."
) from None
protocols = self.resolver.protocols(target)
# Build the translator.
anno_name = get_unique_name(source)
target_name = get_unique_name(target)
func_name = self._get_name(source, target)
oname = "o"
ctx: Dict[str, Any] = {target_name: target, anno_name: source}
with Block(ctx) as main:
with main.f(func_name, Block.p(oname)) as func:
args = ", ".join(
self._iter_field_assigns(fields_to_pass, oname, protocols, ctx)
)
func.l(f"{Keyword.RET} {target_name}({args})")
trans = main.compile(name=func_name, ns=ctx)
return trans
def factory(self, annotation: "Annotation", target: Type) -> "TranslatorT":
"""Generate a translator for :py:class:`typic.Annotation` -> ``type``."""
return self._compile_translator(annotation.resolved, target)
|
# -*- coding: utf-8 -*-
from django.middleware.cache import UpdateCacheMiddleware, FetchFromCacheMiddleware
from django.core.cache import cache
from django.conf import settings
from django.utils.encoding import iri_to_uri
from django.utils.cache import get_max_age, patch_response_headers
from django.utils.translation import get_language
from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
import hashlib
import warnings
md5_constructor = hashlib.md5
md5_hmac = md5_constructor
sha_constructor = hashlib.sha1
sha_hmac = sha_constructor
def get_cache_key(request, key_prefix=None):
"""
depending on user, request-method gererate a key with respect to
GET with querystring and POST with data
"""
if key_prefix is None:
key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
if request.method in ('GET', 'HEAD'):
method = 'GET'
content = md5_constructor(request.GET.urlencode())
elif request.method == 'POST':
method = 'POST'
content = md5_constructor(request.raw_post_data)
else:
method = ''
content = md5_constructor()
path = md5_constructor(iri_to_uri(request.path))
if request.user.is_authenticated:
user = iri_to_uri(request.user)
else:
user = ''
# on response lang was DE again although on request it was EN, so cache that :-)
if hasattr(request, '_cache_lang'):
lang = request._cache_lang
else:
lang = get_language()
request._cache_lang = lang
return '%s.%s.%s.%s.%s.%s.%s' % (
request.get_host(), key_prefix, lang, method, user, path.hexdigest(), content.hexdigest())
class yatsUpdateCacheMiddleware(UpdateCacheMiddleware):
"""
extending djangos standard cache mechanism for POST
"""
def process_response(self, request, response):
"""Sets the cache, if needed."""
if not self._should_update_cache(request, response):
# We don't need to update the cache, just return.
return response
if response.streaming or response.status_code != 200:
return response
# Try to get the timeout from the "max-age" section of the "Cache-
# Control" header before reverting to using the default cache_timeout
# length.
timeout = get_max_age(response)
if timeout == None:
timeout = self.cache_timeout
elif timeout == 0:
# max-age was set to 0, don't bother caching.
return response
patch_response_headers(response, timeout)
if timeout:
#cache_key = learn_cache_key(request, response, timeout, self.key_prefix, cache=self.cache)
cache_key = get_cache_key(request, key_prefix=None)
if hasattr(response, 'render') and callable(response.render):
response.add_post_render_callback(
lambda r: self.cache.set(cache_key, r, timeout)
)
else:
self.cache.set(cache_key, response, timeout)
return response
class yatsFetchFromCacheMiddleware(FetchFromCacheMiddleware):
"""
extending djangos standard cache mechanism for POST
"""
def process_request(self, request):
"""
Checks whether the page is already cached and returns the cached
version if available.
"""
if not request.method in ('GET', 'HEAD'):
request._cache_update_cache = False
return None # Don't bother checking the cache.
# try and get the cached GET response
#cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)
cache_key = get_cache_key(request, self.key_prefix)
if cache_key is None:
request._cache_update_cache = True
return None # No cache information available, need to rebuild.
response = self.cache.get(cache_key, None)
# if it wasn't found and we are looking for a HEAD, try looking just for that
if response is None and request.method == 'HEAD':
#cache_key = get_cache_key(request, self.key_prefix, 'HEAD', cache=self.cache)
cache_key = get_cache_key(request, self.key_prefix)
response = self.cache.get(cache_key, None)
if response is None:
request._cache_update_cache = True
return None # No cache information available, need to rebuild.
# hit, return cached response
request._cache_update_cache = False
return response
class yatsCacheMiddleware(yatsUpdateCacheMiddleware, yatsFetchFromCacheMiddleware):
"""
Cache middleware that provides basic behavior for many simple sites.
Also used as the hook point for the cache decorator, which is generated
using the decorator-from-middleware utility.
"""
def __init__(self, cache_timeout=None, cache_anonymous_only=None, **kwargs):
# We need to differentiate between "provided, but using default value",
# and "not provided". If the value is provided using a default, then
# we fall back to system defaults. If it is not provided at all,
# we need to use middleware defaults.
cache_kwargs = {}
try:
self.key_prefix = kwargs['key_prefix']
if self.key_prefix is not None:
cache_kwargs['KEY_PREFIX'] = self.key_prefix
else:
self.key_prefix = ''
except KeyError:
self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
cache_kwargs['KEY_PREFIX'] = self.key_prefix
try:
self.cache_alias = kwargs['cache_alias']
if self.cache_alias is None:
self.cache_alias = DEFAULT_CACHE_ALIAS
if cache_timeout is not None:
cache_kwargs['TIMEOUT'] = cache_timeout
except KeyError:
self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
if cache_timeout is None:
cache_kwargs['TIMEOUT'] = settings.CACHE_MIDDLEWARE_SECONDS
else:
cache_kwargs['TIMEOUT'] = cache_timeout
if cache_anonymous_only is None:
self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False)
else:
self.cache_anonymous_only = cache_anonymous_only
if self.cache_anonymous_only:
msg = "CACHE_MIDDLEWARE_ANONYMOUS_ONLY has been deprecated and will be removed in Django 1.8."
warnings.warn(msg, PendingDeprecationWarning, stacklevel=1)
self.cache = get_cache(self.cache_alias, **cache_kwargs)
self.cache_timeout = self.cache.default_timeout
|
__author__ = "<NAME>"
__copyright__ = "Copyright 2022, <NAME>"
__credits__ = ["<NAME>"]
__license__ = "mit"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
from ..token.PDFToken import PDFToken
from .PDFItem import PDFItem
from .PDFNull import PDFNull
# Hints when there is no need to insert a space between two items when encoding.
NO_SPACE = {
"": [
"PDFNull", "PDFCommand", "PDFList", "PDFName", "PDFDictionary",
"PDFString", "PDFHexString", "PDFReference", "PDFNumber"
],
"PDFNumber": [
"PDFList", "PDFName", "PDFString", "PDFHexString", "PDFDictionary"
],
"PDFList": [
"PDFNull", "PDFCommand", "PDFList", "PDFName", "PDFDictionary",
"PDFString", "PDFHexString", "PDFReference", "PDFNumber"
],
"PDFString": [
"PDFNull", "PDFCommand", "PDFList", "PDFName", "PDFDictionary",
"PDFString", "PDFHexString", "PDFReference", "PDFNumber"
],
"PDFHexString": [
"PDFNull", "PDFCommand", "PDFList", "PDFName", "PDFDictionary",
"PDFString", "PDFHexString", "PDFReference", "PDFNumber"
],
"PDFReference": [
"PDFList", "PDFName", "PDFString", "PDFHexString", "PDFDictionary"
],
"PDFName": [
"PDFList", "PDFName", "PDFString", "PDFHexString", "PDFDictionary"
],
"PDFCommand": [
"PDFList", "PDFName", "PDFString", "PDFHexString", "PDFDictionary"
],
"PDFNull": [
"PDFList", "PDFName", "PDFString", "PDFHexString", "PDFDictionary"
],
}
class PDFList(PDFItem):
"""A PDF list"""
def __init__(self, items: list):
"""Creates a PDF list.
If the items parameter is not a list, it is placed in a list that will
become the list of the PDFList object.
:param items: The items of the list
:type items: list or other type
"""
if type(items) != list:
items = [items]
self.items = items
def __eq__(self, other):
"""Equality operator for PDFList.
A PDFList is:
- equal to any other PDFList with the same list
- equal to list with the same list
- different from any other PDFToken subclass
Comparing a PDFList with anything else is not implemented.
:param other: The object to compare to our current object
:type other: any
:return: True or False or NotImplemented
:type: bool
"""
if isinstance(other, PDFList):
return self.items == other.items
elif isinstance(other, list):
return self.items == other
elif isinstance(other, PDFToken):
return False
else:
return NotImplemented
def __bool__(self):
"""A PDFList is True if it contains items, False otherwise."""
return self.items != None and len(self.items) > 0
def __len__(self):
return self.items.__len__()
def __getitem__(self, items):
return self.items.__getitem__(items)
def __iter__(self):
return self.items.__iter__()
def __next__(self):
return self.items.__next__()
def is_null(self) -> bool:
for item in self.items:
if type(item) != PDFNull:
return False
return True
def encode(self) -> bytes:
output = b"["
previous = ""
for value in self.items:
current = value.__class__.__name__
if previous in NO_SPACE and current in NO_SPACE[previous]:
output += b"%s" % value.encode()
else:
output += b" %s" % value.encode()
previous = current
output += b"]"
return output
|
<filename>web/core/models.py
import datetime
from django.db import models
from django.conf import settings
from django.utils import timezone
from django.contrib.auth import get_user_model
import hashlib
usermodel = get_user_model()
class Entity(models.Model):
PRODUCER = 'Producteur'
OPERATOR = 'Opérateur'
TRADER = 'Trader'
ADMIN = 'Administration'
AUDITOR = 'Auditor'
EXTERNAL_ADMIN = 'Administration Externe'
ENTITY_TYPES = ((PRODUCER, 'Producteur'), (OPERATOR, 'Opérateur'),
(ADMIN, 'Administration'), (TRADER, 'Trader'),
(AUDITOR, 'Auditeur'), (EXTERNAL_ADMIN, EXTERNAL_ADMIN),
('Unknown', 'Unknown'))
name = models.CharField(max_length=64, unique=True)
date_added = models.DateTimeField(auto_now_add=True)
entity_type = models.CharField(max_length=64, choices=ENTITY_TYPES, default='Unknown')
parent_entity = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE)
has_mac = models.BooleanField(default=False)
has_trading = models.BooleanField(default=False)
legal_name = models.CharField(max_length=128, blank=True, default='')
registration_id = models.CharField(max_length=64, blank=True, default='')
sustainability_officer_phone_number = models.CharField(max_length=32, blank=True, default='')
sustainability_officer = models.CharField(max_length=256, blank=True, default='')
registered_address = models.TextField(blank=True, default='')
hash = models.CharField(max_length=32, null=True, blank=True, default='')
default_certificate = models.CharField(max_length=64, null=True, blank=True, default='')
notifications_enabled = models.BooleanField(default=False)
def __str__(self):
return self.name
def natural_key(self):
d = {'name': self.name, 'id': self.id, 'entity_type': self.entity_type, 'has_mac': self.has_mac, 'has_trading': self.has_trading,
'legal_name': self.legal_name, 'registration_id': self.registration_id,
'sustainability_officer': self.sustainability_officer, 'sustainability_officer_phone_number': self.sustainability_officer_phone_number,
'registered_address': self.registered_address, 'default_certificate': self.default_certificate}
if self.entity_type == Entity.EXTERNAL_ADMIN:
d['ext_admin_pages'] = [e.right for e in self.externaladminrights_set.all()]
return d
def url_friendly_name(self):
return self.name.replace(' ', '').upper()
def save(self, *args, **kwargs):
date_added = self.date_added
if not date_added:
date_added = datetime.date.today()
data = self.name + self.entity_type + date_added.strftime('%Y%m%d')
hash = hashlib.md5(data.encode('utf-8')).hexdigest()
self.hash = hash
super(Entity, self).save(*args, **kwargs)
class Meta:
db_table = 'entities'
verbose_name = 'Entity'
verbose_name_plural = 'Entities'
class UserPreferences(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
default_entity = models.ForeignKey(Entity, blank=True, null=True, on_delete=models.SET_NULL)
def __str__(self):
return self.user.email
class Meta:
db_table = 'users_preferences'
verbose_name = 'User Preference'
verbose_name_plural = 'User Preferences'
class UserRights(models.Model):
RO = 'RO'
RW = 'RW'
ADMIN = 'ADMIN'
AUDITOR = 'AUDITOR'
ROLES = ((RO, 'Lecture Seule'), (RW, 'Lecture/Écriture'), (ADMIN, 'Administrateur'), (AUDITOR, 'Auditeur'))
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
entity = models.ForeignKey(Entity, on_delete=models.CASCADE)
date_added = models.DateTimeField(auto_now_add=True)
role = models.CharField(max_length=32, choices=ROLES, default=RO)
expiration_date = models.DateTimeField(null=True, blank=True)
def __str__(self):
return '%s - %s' % (self.user.email, self.entity.name)
def natural_key(self):
return {'name': self.user.name, 'email': self.user.email, 'entity': self.entity.natural_key(),
'role': self.role, 'expiration_date': self.expiration_date}
class Meta:
db_table = 'users_rights'
verbose_name = 'User Right'
verbose_name_plural = 'Users Rights'
class UserRightsRequests(models.Model):
STATUS_TYPES = (('PENDING', 'En attente de validation'), ('ACCEPTED', 'Accepté'), ('REJECTED', 'Refusé'), ('REVOKED', 'Révoqué'))
RO = 'RO'
RW = 'RW'
ADMIN = 'ADMIN'
AUDITOR = 'AUDITOR'
ROLES = ((RO, 'Lecture Seule'), (RW, 'Lecture/Écriture'), (ADMIN, 'Administrateur'), (AUDITOR, 'Auditeur'))
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
entity = models.ForeignKey(Entity, on_delete=models.CASCADE)
date_requested = models.DateTimeField(auto_now_add=True)
status = models.CharField(max_length=32, choices=STATUS_TYPES, default='PENDING')
comment = models.TextField(blank=True, null=True)
role = models.CharField(max_length=32, choices=ROLES, default=RO)
expiration_date = models.DateTimeField(null=True, blank=True)
def natural_key(self):
return {'id': self.id, 'user': self.user.natural_key(), 'entity': self.entity.natural_key(),
'date_requested': self.date_requested, 'status': self.status, 'comment': self.comment,
'role': self.role, 'expiration_date': self.expiration_date}
class Meta:
db_table = 'users_rights_requests'
verbose_name = 'User Right Request'
verbose_name_plural = 'Users Rights Requests'
class Biocarburant(models.Model):
name = models.CharField(max_length=64)
name_en = models.CharField(max_length=64)
description = models.CharField(max_length=128)
date_added = models.DateField(default=timezone.now)
code = models.CharField(max_length=16, unique=True)
pci_kg = models.FloatField(default=0)
pci_litre = models.FloatField(default=0)
masse_volumique = models.FloatField(default=0)
is_alcool = models.BooleanField(default=False)
is_graisse = models.BooleanField(default=False)
is_displayed = models.BooleanField(default=True)
compatible_essence = models.BooleanField(default=False)
compatible_diesel = models.BooleanField(default=False)
def __str__(self):
return self.name
def __eq__(self, other):
return self.code == other
def __hash__(self):
return super().__hash__()
def natural_key(self):
return {'code': self.code, 'name': self.name}
class Meta:
db_table = 'biocarburants'
verbose_name = 'Biocarburant'
verbose_name_plural = 'Biocarburants'
class MatierePremiere(models.Model):
CONV = 'CONV'
IXA = 'ANN-IX-A'
IXB = 'ANN-IX-B'
TALLOL = 'TALLOL'
OTHER = 'OTHER'
MP_CATEGORIES = ((CONV, 'Conventionnel'), (IXA, 'ANNEXE IX-A'), (IXB, 'ANNEXE IX-B'), (TALLOL, 'Tallol'), (OTHER, 'Autre'))
name = models.CharField(max_length=128)
name_en = models.CharField(max_length=128)
description = models.CharField(max_length=128)
date_added = models.DateField(default=timezone.now)
code = models.CharField(max_length=64, unique=True)
compatible_alcool = models.BooleanField(default=False)
compatible_graisse = models.BooleanField(default=False)
is_double_compte = models.BooleanField(default=False)
is_huile_vegetale = models.BooleanField(default=False)
is_displayed = models.BooleanField(default=True)
category = models.CharField(max_length=32, choices=MP_CATEGORIES, default='CONV')
def __str__(self):
return self.name
def natural_key(self):
return {'code': self.code, 'name': self.name, 'is_double_compte': self.is_double_compte, 'category': self.category}
class Meta:
db_table = 'matieres_premieres'
verbose_name = 'Matiere Premiere'
verbose_name_plural = 'Matieres Premieres'
class Pays(models.Model):
code_pays = models.CharField(max_length=64)
name = models.CharField(max_length=128)
name_en = models.CharField(max_length=128)
date_added = models.DateField(default=timezone.now)
is_in_europe = models.BooleanField(default=False)
def __str__(self):
return self.name
def natural_key(self):
return {'code_pays': self.code_pays, 'name': self.name, 'name_en': self.name_en, 'is_in_europe': self.is_in_europe}
class Meta:
db_table = 'pays'
verbose_name = 'Pays'
verbose_name_plural = 'Pays'
class Depot(models.Model):
EFS = 'EFS'
EFPE = 'EFPE'
OTHER = 'OTHER'
OILDEPOT = 'OIL DEPOT'
BIOFUELDEPOT = 'BIOFUEL DEPOT'
TYPE_DEPOT = ((EFS, 'EFS'), (EFPE, 'EFPE'), (OILDEPOT, "OIL DEPOT"), (BIOFUELDEPOT, "BIOFUEL DEPOT"), (OTHER, 'Autre'),)
name = models.CharField(max_length=128, null=False, blank=False)
city = models.CharField(max_length=128, null=True, blank=True)
depot_id = models.CharField(max_length=32, null=False, blank=False)
country = models.ForeignKey(Pays, null=True, blank=False, on_delete=models.SET_NULL)
depot_type = models.CharField(max_length=32, choices=TYPE_DEPOT, default=OTHER)
address = models.CharField(max_length=128, blank=True)
postal_code = models.CharField(max_length=32, blank=True)
gps_coordinates = models.CharField(max_length=64, blank=True, null=True, default=None)
def __str__(self):
return self.name
def natural_key(self):
return {'depot_id': self.depot_id, 'name': self.name, 'city': self.city, 'country': self.country.natural_key(),
'depot_type': self.depot_type, 'address': self.address, 'postal_code': self.postal_code}
class Meta:
db_table = 'depots'
verbose_name = 'Dépôt'
verbose_name_plural = 'Dépôts'
class EntityDepot(models.Model):
OWN = 'OWN'
THIRD_PARTY = 'THIRD_PARTY'
PROCESSING = 'PROCESSING'
TYPE_OWNERSHIP = ((OWN, 'Propre'), (THIRD_PARTY, 'Tiers'), (PROCESSING, 'Processing'))
entity = models.ForeignKey(Entity, null=False, blank=False, on_delete=models.CASCADE)
depot = models.ForeignKey(Depot, null=False, blank=False, on_delete=models.CASCADE)
ownership_type = models.CharField(max_length=32, choices=TYPE_OWNERSHIP, default=THIRD_PARTY)
blending_is_outsourced = models.BooleanField(default=False)
blender = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.CASCADE, related_name='blender')
def __str__(self):
return str(self.id)
def natural_key(self):
return {'depot': self.depot.natural_key(), 'ownership_type': self.ownership_type, 'blending_is_outsourced': self.blending_is_outsourced, 'blender': self.blender.natural_key() if self.blender else None}
class Meta:
db_table = 'entity_depot'
verbose_name = 'Dépôt Entité'
verbose_name_plural = 'Dépôts Entité'
from producers.models import ProductionSite
# deprecated. Use LotV2
class Lot(models.Model):
carbure_id = models.CharField(max_length=64, blank=True, default='')
class Meta:
db_table = 'lots'
class LotV2(models.Model):
DRAFT = 'Draft'
VALIDATED = 'Validated'
LOT_STATUS = ((DRAFT, 'Brouillon'), (VALIDATED, 'Validé'))
SOURCE_CHOICES = (('EXCEL', 'Excel'), ('MANUAL', 'Manual'))
period = models.CharField(max_length=64, blank=True, default='')
year = models.IntegerField(blank=False, null=False, default=0)
carbure_id = models.CharField(max_length=64, blank=True, default='')
# producer
producer_is_in_carbure = models.BooleanField(default=True)
carbure_producer = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL, related_name='producer_lotv2')
unknown_producer = models.CharField(max_length=64, blank=True, null=True, default='')
production_site_is_in_carbure = models.BooleanField(default=True)
carbure_production_site = models.ForeignKey(ProductionSite, null=True, blank=True, on_delete=models.SET_NULL)
carbure_production_site_reference = models.CharField(max_length=64, blank=True, null=True, default='')
unknown_production_site = models.CharField(max_length=64, blank=True, null=True, default='')
unknown_production_country = models.ForeignKey(Pays, null=True, blank=True, on_delete=models.SET_NULL, related_name='unknown_production_site_country')
unknown_production_site_com_date = models.DateField(blank=True, null=True)
unknown_production_site_reference = models.CharField(max_length=64, blank=True, null=True, default='')
unknown_production_site_dbl_counting = models.CharField(max_length=64, blank=True, null=True, default='')
unknown_supplier = models.CharField(max_length=64, blank=True, null=True, default='')
unknown_supplier_certificate = models.CharField(max_length=64, blank=True, null=True, default='')
# lot details
volume = models.FloatField(default=0.0)
remaining_volume = models.FloatField(default=0.0)
matiere_premiere = models.ForeignKey(MatierePremiere, null=True, on_delete=models.SET_NULL)
biocarburant = models.ForeignKey(Biocarburant, null=True, on_delete=models.SET_NULL)
pays_origine = models.ForeignKey(Pays, null=True, on_delete=models.SET_NULL)
# GHG values
eec = models.FloatField(default=0.0)
el = models.FloatField(default=0.0)
ep = models.FloatField(default=0.0)
etd = models.FloatField(default=0.0)
eu = models.FloatField(default=0.0)
esca = models.FloatField(default=0.0)
eccs = models.FloatField(default=0.0)
eccr = models.FloatField(default=0.0)
eee = models.FloatField(default=0.0)
ghg_total = models.FloatField(default=0.0)
ghg_reference = models.FloatField(default=0.0)
ghg_reduction = models.FloatField(default=0.0)
ghg_reference_red_ii = models.FloatField(default=0.0)
ghg_reduction_red_ii = models.FloatField(default=0.0)
# other
status = models.CharField(max_length=64, choices=LOT_STATUS, default='Draft')
source = models.CharField(max_length=32, choices=SOURCE_CHOICES, default='Manual')
added_by = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL)
added_by_user = models.ForeignKey(usermodel, null=True, blank=True, on_delete=models.SET_NULL)
added_time = models.DateTimeField(auto_now_add=True)
# lot has been split into many sublots ?
parent_lot = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE)
is_split = models.BooleanField(default=False)
# lot has been fused
is_fused = models.BooleanField(default=False)
fused_with = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, related_name='lotv2_fused_with')
# lot has been transformed (ETBE)
is_transformed = models.BooleanField(default=False)
# when True, parent_lot will be set
# entity responsible for the original data
data_origin_entity = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL, related_name='data_origin_entity')
# sanity checks
blocking_sanity_checked_passed = models.BooleanField(default=False)
nonblocking_sanity_checked_passed = models.BooleanField(default=False)
is_valid = models.BooleanField(default=False)
def natural_key(self):
return {'id': self.id, 'period': self.period, 'carbure_id': self.carbure_id, 'producer_is_in_carbure': self.producer_is_in_carbure, 'carbure_producer': self.carbure_producer.natural_key() if self.carbure_producer else None,
'unknown_producer': self.unknown_producer, 'production_site_is_in_carbure': self.production_site_is_in_carbure, 'carbure_production_site': self.carbure_production_site.natural_key() if self.carbure_production_site else None,
'unknown_production_site': self.unknown_production_site, 'unknown_production_country': self.unknown_production_country.natural_key() if self.unknown_production_country else None,
'unknown_production_site_com_date': self.unknown_production_site_com_date, 'unknown_production_site_reference': self.unknown_production_site_reference,
'unknown_production_site_dbl_counting': self.unknown_production_site_dbl_counting, 'volume': round(self.volume, 2), 'remaining_volume': round(self.remaining_volume, 2), 'matiere_premiere': self.matiere_premiere.natural_key() if self.matiere_premiere else None,
'biocarburant': self.biocarburant.natural_key() if self.biocarburant else None, 'pays_origine': self.pays_origine.natural_key() if self.pays_origine else None,
'eec': self.eec, 'el': self.el, 'ep': self.ep, 'etd': self.etd, 'eu': self.eu, 'esca': self.esca, 'eccs': self.eccs, 'eccr': self.eccr, 'eee': self.eee,
'ghg_total': self.ghg_total, 'ghg_reference': self.ghg_reference, 'ghg_reduction': self.ghg_reduction, 'status': self.status, 'source': self.source,
'parent_lot': self.parent_lot.natural_key() if self.parent_lot else None, 'is_split': self.is_split, 'is_fused': self.is_fused, 'fused_with': self.fused_with.natural_key() if self.fused_with else None,
'data_origin_entity': self.data_origin_entity.natural_key() if self.data_origin_entity else None, 'added_by': self.added_by.natural_key() if self.added_by else None, 'is_transformed': self.is_transformed,
'unknown_supplier': self.unknown_supplier, 'unknown_supplier_certificate': self.unknown_supplier_certificate, 'carbure_production_site_reference': self.carbure_production_site_reference, 'added_time': self.added_time,
'ghg_reference_red_ii': self.ghg_reference_red_ii, 'ghg_reduction_red_ii': self.ghg_reduction_red_ii}
def __str__(self):
return str(self.id)
class Meta:
db_table = 'lots_v2'
verbose_name = 'LotV2'
verbose_name_plural = 'LotsV2'
indexes = [
models.Index(fields=["status"]),
models.Index(fields=["added_by"]),
models.Index(fields=["period"]),
models.Index(fields=["biocarburant"]),
models.Index(fields=["matiere_premiere"]),
models.Index(fields=["pays_origine"]),
models.Index(fields=["carbure_production_site"]),
models.Index(fields=["unknown_production_site"]),
models.Index(fields=["year"]),
]
class LotTransaction(models.Model):
# Livraison "standard" - biocarburant uniquement
BIOFUEL_DELIVERY = "BIOFUEL_DELIVERY"
# Mise a consommation / Utilisation directe du biocarburant sans incorporation
MAC = "MAC"
# livraison d'un camion de carburants avec Bio déjà incorporé
DIRECT_DELIVERY = "DIRECT_DELIVERY"
TRANSACTION_TYPES = ((BIOFUEL_DELIVERY, BIOFUEL_DELIVERY), (MAC, MAC), (DIRECT_DELIVERY, DIRECT_DELIVERY))
# Statuts des transactions
PENDING = 'N'
ACCEPTED = 'A'
REJECTED = 'R'
TOFIX = 'AC'
FIXED = 'AA'
FROZEN = 'F'
DELIVERY_STATUS = ((PENDING, 'En attente'), (ACCEPTED, 'Accepté'), (REJECTED, 'Refusé'), (TOFIX, 'À corriger'), (FIXED, 'Corrigé'), (FROZEN, 'Déclaré'))
lot = models.ForeignKey(LotV2, null=False, blank=False, on_delete=models.CASCADE, related_name='tx_lot')
# vendor / producer
carbure_vendor = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL, related_name='vendor_transaction')
carbure_vendor_certificate = models.CharField(max_length=64, blank=True, null=True, default='')
# client / delivery
dae = models.CharField(max_length=128, blank=True, default='')
client_is_in_carbure = models.BooleanField(default=True)
carbure_client = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL, related_name='client_transaction')
unknown_client = models.CharField(max_length=64, blank=True, default='')
delivery_date = models.DateField(blank=True, null=True)
delivery_site_is_in_carbure = models.BooleanField(default=True)
carbure_delivery_site = models.ForeignKey(Depot, null=True, blank=True, on_delete=models.SET_NULL)
unknown_delivery_site = models.CharField(max_length=64, blank=True, default='')
unknown_delivery_site_country = models.ForeignKey(Pays, null=True, blank=True, on_delete=models.SET_NULL, related_name='unknown_delivery_site_country')
delivery_status = models.CharField(max_length=64, choices=DELIVERY_STATUS, default='N')
# ghg impact
etd_impact = models.FloatField(default=0.0)
ghg_total = models.FloatField(default=0.0)
ghg_reduction = models.FloatField(default=0.0)
# other
champ_libre = models.TextField(blank=True, null=True, default='')
# mise a consommation?
is_mac = models.BooleanField(default=False)
transaction_type = models.CharField(max_length=32, choices=TRANSACTION_TYPES, default=BIOFUEL_DELIVERY)
# this PoS is part of a multiple PoS batch
is_batch = models.BooleanField(default=False)
# transaction generated by carbure stock-optimisation
generated_by_carbure = models.BooleanField(default=False)
# this PoS has been forwarded by an Operator to another Operator (outsourced blending)
# or this PoS has been forwarded by a Trader to a client (trading without storage, the trader is only an intermediary)
is_forwarded = models.BooleanField(default=False)
parent_tx = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, related_name="parent")
child_tx = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL, related_name="child")
# this PoS has been received by a producer with trading or a trader
# this flag will make it easier to find "stock" lots
is_stock = models.BooleanField(default=False)
# admin / auditor checks & filters
hidden_by_admin = models.BooleanField(default=False)
hidden_by_auditor = models.BooleanField(default=False)
highlighted_by_admin = models.BooleanField(default=False)
highlighted_by_auditor = models.BooleanField(default=False)
# duplicates
potential_duplicate = models.BooleanField(default=False)
def __str__(self):
return str(self.id)
def natural_key(self, admin=False):
d = {'lot': self.lot.natural_key(), 'carbure_vendor': self.carbure_vendor.natural_key() if self.carbure_vendor else None, 'carbure_vendor_certificate': self.carbure_vendor_certificate,
'dae': self.dae, 'client_is_in_carbure': self.client_is_in_carbure, 'carbure_client': self.carbure_client.natural_key() if self.carbure_client else None,
'unknown_client': self.unknown_client, 'delivery_date': self.delivery_date, 'delivery_site_is_in_carbure': self.delivery_site_is_in_carbure,
'carbure_delivery_site': self.carbure_delivery_site.natural_key() if self.carbure_delivery_site else None, 'unknown_delivery_site': self.unknown_delivery_site,
'unknown_delivery_site_country': self.unknown_delivery_site_country.natural_key() if self.unknown_delivery_site_country else None, 'delivery_status': self.delivery_status,
'champ_libre': self.champ_libre, 'is_mac': self.is_mac, 'is_batch': self.is_batch,
'id': self.id, 'is_forwarded': self.is_forwarded, 'parent_tx': self.parent_tx_id, 'child_tx': self.child_tx.natural_key() if (self.child_tx and self.child_tx_id != self.id) else None}
if admin:
d['hidden_by_admin'] = self.hidden_by_admin
d['highlighted_by_admin'] = self.highlighted_by_admin
d['hidden_by_auditor'] = self.hidden_by_auditor
d['highlighted_by_auditor'] = self.highlighted_by_auditor
if self.lot.is_split: # trading with storage - we hide producer data
if d['lot']['carbure_producer']:
d['lot']['carbure_producer']['name'] = "Confidentiel"
d['lot']['carbure_production_site_reference'] = "Confidentiel"
d['lot']['unknown_producer'] = "Confidentiel"
d['lot']['unknown_production_site_reference'] = "Confidentiel"
return d
class Meta:
db_table = 'transactions'
verbose_name = 'Transaction'
verbose_name_plural = 'Transactions'
indexes = [
models.Index(fields=["carbure_vendor"]),
models.Index(fields=["carbure_client"]),
models.Index(fields=["delivery_status"]),
models.Index(fields=["unknown_client"]),
models.Index(fields=["is_forwarded"]),
models.Index(fields=["is_mac"]),
models.Index(fields=["carbure_delivery_site"]),
models.Index(fields=["unknown_delivery_site"]),
]
class TransactionComment(models.Model):
COMMENT_TOPIC = (('SUSTAINABILITY', 'Durabilité'), ('TX', 'Transaction'), ('BOTH', 'Les deux'))
entity = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL)
topic = models.CharField(max_length=24, choices=COMMENT_TOPIC, default='BOTH')
tx = models.ForeignKey(LotTransaction, on_delete=models.CASCADE)
comment = models.TextField()
def __str__(self):
return str(self.comment)
def natural_key(self):
return {'entity': self.entity.natural_key(), 'topic':self.topic, 'comment':self.comment}
class Meta:
db_table = 'tx_comments'
verbose_name = 'TransactionComment'
verbose_name_plural = 'TransactionComments'
class AdminTransactionComment(models.Model):
tx = models.ForeignKey(LotTransaction, on_delete=models.CASCADE)
comment = models.TextField()
datetime = models.DateTimeField(auto_now_add=True)
is_visible_by_admin = models.BooleanField(default=True)
is_visible_by_auditor = models.BooleanField(default=False)
entity = models.ForeignKey(Entity, on_delete=models.CASCADE, null=True)
def __str__(self):
return str(self.comment)
def natural_key(self):
return {'comment': self.comment, 'datetime': self.datetime,
'entity': self.entity.natural_key() if self.entity else None}
class Meta:
db_table = 'admin_tx_comments'
verbose_name = 'AdminTransactionComment'
verbose_name_plural = 'AdminTransactionComments'
class Control(models.Model):
STATUS = [("OPEN", "Ouvert"), ("CLOSED", "Clôturé")]
tx = models.ForeignKey(LotTransaction, on_delete=models.CASCADE)
status = models.CharField(max_length=32, choices=STATUS, default="OPEN")
opened_at = models.DateTimeField(auto_now_add=True)
last_update = models.DateTimeField(auto_now=True)
def natural_key(self):
return {'tx': self.tx.natural_key(), 'status': self.status, 'opened_at': self.opened_at, 'last_update': self.last_update}
class Meta:
db_table = 'controls'
verbose_name = 'Contrôle Lot'
verbose_name_plural = 'Contrôles Lots'
class ControlFiles(models.Model):
control = models.ForeignKey(Control, on_delete=models.CASCADE)
date_added = models.DateField(auto_now_add=True)
file = models.FileField(null=True, blank=True)
class Meta:
db_table = 'control_files'
verbose_name = 'Contrôle - Justificatif'
verbose_name_plural = 'Contrôles - Justificatifs'
class ControlMessages(models.Model):
control = models.ForeignKey(Control, on_delete=models.CASCADE)
entity = models.ForeignKey(Entity, on_delete=models.SET_NULL, null=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True)
message = models.TextField(blank=False, null=False)
dt_added = models.DateTimeField(auto_now_add=True)
def natural_key(self):
return {'entity': self.entity.natural_key(), 'message': self.message, 'dt_addded': self.dt_added}
class Meta:
db_table = 'control_messages'
verbose_name = 'Contrôle - Message'
verbose_name_plural = 'Contrôles - Messages'
class SustainabilityDeclaration(models.Model):
entity = models.ForeignKey(Entity, on_delete=models.CASCADE)
declared = models.BooleanField(default=False)
checked = models.BooleanField(default=False)
deadline = models.DateField(default=datetime.datetime.now, blank=True)
period = models.DateField(default=datetime.datetime.now, blank=True)
reminder_count = models.IntegerField(default=0)
def natural_key(self):
return {'id': self.id,'entity': self.entity.natural_key(), 'declared': self.declared, 'period': self.period, 'deadline': self.deadline, 'checked': self.checked, 'month': self.period.month, 'year': self.period.year, 'reminder_count': self.reminder_count}
class Meta:
db_table = 'declarations'
verbose_name = ' Déclaration de Durabilité'
verbose_name_plural = ' Déclarations de Durabilité'
class ETBETransformation(models.Model):
previous_stock = models.ForeignKey(LotTransaction, null=False, blank=False, on_delete=models.CASCADE, related_name='previous_stock')
new_stock = models.ForeignKey(LotTransaction, null=False, blank=False, on_delete=models.CASCADE, related_name='new_stock')
volume_ethanol = models.FloatField(null=False, blank=False, default=0.0)
volume_etbe = models.FloatField(null=False, blank=False, default=0.0)
volume_etbe_eligible = models.FloatField(null=False, blank=False, default=0.0)
volume_denaturant = models.FloatField(null=False, blank=False, default=0.0)
added_by = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL)
added_by_user = models.ForeignKey(usermodel, null=True, blank=True, on_delete=models.SET_NULL)
added_time = models.DateTimeField(auto_now_add=True)
def natural_key(self):
return {'previous': self.previous_stock.natural_key(), 'new': self.new_stock.natural_key(), 'volume_ethanol': self.volume_ethanol, 'volume_etbe': self.volume_etbe, 'volume_denaturant': self.volume_denaturant, 'volume_etbe_eligible': self.volume_etbe_eligible,
'added_by': self.added_by.natural_key(), 'added_by_user': self.added_by_user.natural_key(), 'added_time': self.added_time}
class Meta:
db_table = 'etbe_transformations'
verbose_name = 'Transformation ETBE'
verbose_name_plural = 'Transformations ETBE'
class GenericError(models.Model):
error = models.CharField(max_length=256, null=False, blank=False)
display_to_creator = models.BooleanField(default=False)
display_to_recipient = models.BooleanField(default=False)
display_to_admin = models.BooleanField(default=False)
display_to_auditor = models.BooleanField(default=False)
acked_by_creator = models.BooleanField(default=False)
acked_by_recipient = models.BooleanField(default=False)
acked_by_admin = models.BooleanField(default=False)
acked_by_auditor = models.BooleanField(default=False)
highlighted_by_admin = models.BooleanField(default=False)
highlighted_by_auditor = models.BooleanField(default=False)
is_blocking = models.BooleanField(default=False)
tx = models.ForeignKey(LotTransaction, null=False, blank=False, on_delete=models.CASCADE)
field = models.CharField(max_length=64, null=True, blank=True)
fields = models.JSONField(null=True, blank=True)
value = models.CharField(max_length=128, null=True, blank=True)
extra = models.CharField(max_length=256, null=True, blank=True)
def natural_key(self):
return {'error': self.error,
'display_to_creator': self.display_to_creator, 'display_to_recipient': self.display_to_recipient,
'display_to_admin': self.display_to_admin, 'display_to_auditor': self.display_to_auditor,
'acked_by_creator': self.acked_by_creator, 'acked_by_recipient': self.acked_by_recipient,
'acked_by_admin': self.acked_by_admin, 'acked_by_auditor': self.acked_by_auditor,
'highlighted_by_admin': self.highlighted_by_admin, 'highlighted_by_auditor': self.highlighted_by_auditor,
'is_blocking': self.is_blocking, 'tx_id': self.tx_id, 'field': self.field, 'fields': self.fields,
'value': self.value, 'extra': self.extra}
class Meta:
db_table = 'generic_errors'
verbose_name = 'Generic Error'
verbose_name_plural = 'Generic Errors'
class TransactionUpdateHistory(models.Model):
ADD = "ADD"
REMOVE = "REMOVE"
UPDATE = "UPDATE"
TX_HISTORY_TYPES = ((ADD, ADD), (REMOVE, REMOVE), (UPDATE, UPDATE))
tx = models.ForeignKey(LotTransaction, null=False, blank=False, on_delete=models.CASCADE)
datetime = models.DateTimeField(auto_now_add=True)
update_type = models.CharField(max_length=32, null=False, blank=False, choices=TX_HISTORY_TYPES, default=ADD)
field = models.CharField(max_length=64, null=False, blank=False)
value_before = models.TextField(null=True)
value_after = models.TextField(null=True)
modified_by = models.ForeignKey(usermodel, null=True, blank=True, on_delete=models.SET_NULL)
modified_by_entity = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.SET_NULL)
def natural_key(self):
return {'tx_id': self.tx.id, 'update_type': self.update_type, 'datetime': self.datetime, 'field': self.field, 'value_before': self.value_before, 'value_after': self.value_after,
'modified_by': self.modified_by.email if self.modified_by else '', 'entity': self.modified_by_entity.name if self.modified_by_entity else ''}
class Meta:
db_table = 'transactions_updates'
verbose_name = 'Transaction Update'
verbose_name_plural = 'Transaction Updates'
class EmailNotification(models.Model):
CORRECTION_REQUEST = "CORRECTION_REQUEST"
CORRECTION_DONE = "CORRECTION_DONE"
LOT_REJECTED = "LOT_REJECTED"
LOT_PENDING = "LOT_PENDING"
DECLARATION_INVALIDATED = "DECLARATION_INVALIDATED"
DECLARATION_VALIDATED = "DECLARATION_VALIDATED"
NOTIFICATION_TYPE = ((CORRECTION_REQUEST, CORRECTION_REQUEST), (CORRECTION_DONE, CORRECTION_DONE),
(LOT_REJECTED, LOT_REJECTED), (LOT_PENDING, LOT_PENDING),
(DECLARATION_INVALIDATED, DECLARATION_INVALIDATED),
(DECLARATION_VALIDATED, DECLARATION_VALIDATED))
datetime = models.DateTimeField(auto_now_add=True)
linked_tx = models.ForeignKey(LotTransaction, null=True, blank=True, on_delete=models.CASCADE)
linked_declaration = models.ForeignKey(SustainabilityDeclaration, null=True, blank=True, on_delete=models.CASCADE)
notif_type = models.CharField(max_length=32, null=False, blank=False, choices=NOTIFICATION_TYPE, default="")
entity = models.ForeignKey(Entity, null=True, blank=True, on_delete=models.CASCADE)
send_copy_to_admin = models.BooleanField(default=False)
sent = models.BooleanField(default=False)
class Meta:
db_table = 'email_notifications'
verbose_name = 'Email Notification'
verbose_name_plural = 'Email Notifications'
class TransactionDistance(models.Model):
starting_point = models.CharField(max_length=64, blank=True, null=True, default=None)
delivery_point = models.CharField(max_length=64, blank=True, null=True, default=None)
distance = models.FloatField(default=0.0)
class Meta:
db_table = 'transaction_distances'
verbose_name = 'Distance'
verbose_name_plural = 'Distances'
class ExternalAdminRights(models.Model):
DOUBLE_COUNTING_AGREEMENT = "DCA"
CUSTOM_STATS_AGRIMER = "AGRIMER"
TIRIB_STATS = "TIRIB"
RIGHTS = ((DOUBLE_COUNTING_AGREEMENT, DOUBLE_COUNTING_AGREEMENT), (CUSTOM_STATS_AGRIMER, CUSTOM_STATS_AGRIMER), (TIRIB_STATS, TIRIB_STATS))
entity = models.ForeignKey(Entity, on_delete=models.CASCADE)
right = models.CharField(max_length=32, choices=RIGHTS, default='', blank=False, null=False)
class Meta:
db_table = 'ext_admin_rights'
verbose_name = 'External Admin Right'
verbose_name_plural = 'External Admin Rights'
|
<filename>Bonus-materials/Anomaly/train.py
import numpy as np
import mxnet as mx
from mxnet import gluon
import glob
import argparse
import os
from six import BytesIO, StringIO
out = 10
class ConvolutionalAutoencoder(gluon.nn.HybridBlock):
def __init__(self):
super(ConvolutionalAutoencoder, self).__init__()
with self.name_scope():
# Encoder
self.encoder = gluon.nn.HybridSequential(prefix="")
with self.encoder.name_scope():
self.encoder.add(gluon.nn.Conv2D(32, 5, padding=0, activation='relu'))
self.encoder.add(gluon.nn.MaxPool2D(2))
self.encoder.add(gluon.nn.Conv2D(32, 5, padding=0, activation='relu'))
self.encoder.add(gluon.nn.MaxPool2D(2))
self.encoder.add(gluon.nn.Dense(100))
self.decoder = gluon.nn.HybridSequential(prefix="")
# Decoder
with self.decoder.name_scope():
self.decoder.add(gluon.nn.Dense(32*22*22, activation='relu'))
self.decoder.add(gluon.nn.HybridLambda(lambda F, x: F.UpSampling(x, scale=2, sample_type='nearest')))
self.decoder.add(gluon.nn.Conv2DTranspose(32, 5, activation='relu'))
self.decoder.add(gluon.nn.HybridLambda(lambda F, x: F.UpSampling(x, scale=2, sample_type='nearest')))
self.decoder.add(gluon.nn.Conv2DTranspose(1, kernel_size=5, activation='sigmoid'))
def hybrid_forward(self, F, x):
x = self.encoder(x)
x = self.decoder[0](x)
# need to reshape ouput feature vector from Dense(32*22*22), before it is upsampled
x = x.reshape((-1,32,22,22))
x = self.decoder[1:](x)
return x
ctx = mx.cpu()
def train(batch_size, epochs, learning_rate, weight_decay):
train = np.load("../input/data/train/input_data.npy")
dataset = gluon.data.ArrayDataset(mx.nd.array(train, dtype=np.float32))
dataloader = gluon.data.DataLoader(dataset, batch_size=batch_size, last_batch='rollover',shuffle=True)
model = ConvolutionalAutoencoder()
model.hybridize()
model.collect_params().initialize(mx.init.Normal(0.01), ctx=ctx)
loss2 = gluon.loss.L2Loss()
optimizer = gluon.Trainer(model.collect_params(), 'adam', {'learning_rate': learning_rate, 'wd': weight_decay})
for epoch in range(epochs):
for img in dataloader:
img = img.as_in_context(ctx)
batch = img.shape[0]
with mx.autograd.record():
output = model(img)
loss = loss2(output, img)
loss.backward()
optimizer.step(batch_size)
print('epoch [{}/{}], loss:{:.4f}'.format(epoch + 1, epochs, mx.nd.mean(loss).asscalar()))
save(model, os.environ['SM_MODEL_DIR'])
return model
def save(model, model_dir):
model.save_parameters('%s/model.params' % model_dir)
def model_fn(model_dir):
model = STSAE()
model.load_parameters("%s/model.params" %model_dir, ctx=ctx)
return model
#def transform_fn(model, data, content_type, accept):
# tmp = np.load(StringIO(data))
# mx_nd_array = mx.nd.array(data)
# mx_nd_array = mx_nd_array.as_in_context(ctx)
# output = model(mx_nd_array)
# np_array = output.asnumpy()
# np.save("output", np_array)
# f = open("output.npy")
# return f.read()
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--batch_size', type=int, default=100)
parser.add_argument('--epochs', type=int, default=10)
parser.add_argument('--learning_rate', type=float, default=0.1)
parser.add_argument('--wd', type=float, default=0.1)
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
train(args.batch_size, args.epochs, args.learning_rate, args.wd)
|
<reponame>MChaus/NeoRender_test_task<gh_stars>1-10
import os
import zipfile
import urllib.request
import torch
import skimage.measure
from .deep_sdf import Decoder
def marching_cubes(
decoder,
latent_vec,
level =0.0,
N=256,
max_batch=32 ** 3
):
''' Return verts, faces, normals, values for given representation.
'''
decoder.eval()
# NOTE: the voxel_origin is actually the (bottom, left, down) corner, not the middle
voxel_origin = [-1, -1, -1]
voxel_size = 2.0 / (N - 1)
overall_index = torch.arange(0, N ** 3, 1, out=torch.LongTensor())
samples = torch.zeros(N ** 3, 4)
# transform first 3 columns
# to be the x, y, z index
samples[:, 2] = overall_index % N
samples[:, 1] = (overall_index.long() // N) % N
samples[:, 0] = ((overall_index.long() // N) // N) % N
# transform first 3 columns
# to be the x, y, z coordinate
samples[:, 0] = (samples[:, 0] * voxel_size) + voxel_origin[2]
samples[:, 1] = (samples[:, 1] * voxel_size) + voxel_origin[1]
samples[:, 2] = (samples[:, 2] * voxel_size) + voxel_origin[0]
num_samples = N ** 3
samples.requires_grad = False
head = 0
while head < num_samples:
print('computing verices {:.2f} %'.format(head / num_samples * 100), end='\r')
sample_subset = samples[head : min(head + max_batch, num_samples), 0:3]
samples[head : min(head + max_batch, num_samples), 3] = (
decode_sdf(decoder, latent_vec, sample_subset)
.squeeze(1)
.detach()
.cpu()
)
head += max_batch
sdf_values = samples[:, 3]
sdf_values = sdf_values.reshape(N, N, N)
pytorch_3d_sdf_tensor = sdf_values.data.cpu()
numpy_3d_sdf_tensor = pytorch_3d_sdf_tensor.numpy()
verts, faces, normals, values = skimage.measure.marching_cubes(
numpy_3d_sdf_tensor, level=level, spacing=[voxel_size] * 3
)
print('\nvertices are ready')
return verts, faces, normals, values
def decode_sdf(decoder, latent_vector, queries):
num_samples = queries.shape[0]
latent_repeat = latent_vector.expand(num_samples, -1)
inputs = torch.cat([latent_repeat, queries], 1)
sdf = decoder(inputs)
return sdf
def download_models(source_url, target_dir, target_file):
print('Downloading ...')
urllib.request.urlretrieve(source_url, filename=target_file)
print('Unzipping ...')
zip_ref = zipfile.ZipFile(target_file, 'r')
zip_ref.extractall(target_dir)
zip_ref.close()
os.remove(target_file)
print('Models were downloaded to {}'.format(target_dir))
def data_loader(path, specs, epochs: list, obj_id=0):
for epoch in epochs:
net_path = os.path.join(path, 'model_{}.pt'.format(epoch))
lat_path = os.path.join(path, 'latent_vecs_{}.pt'.format(epoch))
if not os.path.exists(net_path):
continue
deep_sdf = Decoder(specs['CodeLength'], **specs['NetworkSpecs'])
data = torch.load(net_path)
deep_sdf.load_state_dict(data["model_state_dict"])
latent = torch.load(lat_path)
latent_vec = latent['latent_codes']['weight'][obj_id]
yield deep_sdf, latent_vec |
import asynctest
import pytest
from dbdaora import Query
from dbdaora.exceptions import EntityNotFoundError
@pytest.mark.asyncio
async def test_should_get_from_memory(
repository, serialized_fake_entity, fake_entity
):
await repository.memory_data_source.set(
'fake:fake', serialized_fake_entity
)
entity = await repository.query('fake').entity
assert entity == fake_entity.id
@pytest.mark.asyncio
async def test_should_raise_not_found_error(repository, fake_entity, mocker):
await repository.memory_data_source.delete('fake:fake')
fake_query = Query(repository, memory=True, id=fake_entity.id)
with pytest.raises(EntityNotFoundError) as exc_info:
await repository.query(fake_entity.id).entity
assert exc_info.value.args == (fake_query,)
@pytest.mark.asyncio
async def test_should_raise_not_found_error_when_already_raised_before(
repository, mocker
):
fake_entity = 'fake'
expected_query = Query(repository, memory=True, id=fake_entity)
repository.memory_data_source.get = asynctest.CoroutineMock(
side_effect=[False, True]
)
repository.memory_data_source.set = asynctest.CoroutineMock()
with pytest.raises(EntityNotFoundError) as exc_info:
await repository.query(fake_entity).entity
assert exc_info.value.args == (expected_query,)
assert repository.memory_data_source.get.call_args_list == [
mocker.call('fake:fake'),
]
assert not repository.memory_data_source.set.called
@pytest.mark.asyncio
async def test_should_set_already_not_found_error(repository, mocker):
fake_entity = 'fake'
expected_query = Query(repository, memory=True, id=fake_entity)
repository.fallback_data_source.get = asynctest.CoroutineMock(
return_value=None
)
repository.memory_data_source.get = asynctest.CoroutineMock(
return_value=None
)
repository.memory_data_source.set = asynctest.CoroutineMock()
with pytest.raises(EntityNotFoundError) as exc_info:
await repository.query(fake_entity).entity
assert exc_info.value.args == (expected_query,)
assert repository.fallback_data_source.get.call_args_list == [
mocker.call('fake:fake')
]
assert repository.memory_data_source.set.call_args_list == [
mocker.call('fake:fake', '0')
]
@pytest.mark.asyncio
async def test_should_get_from_fallback(repository, fake_entity):
await repository.memory_data_source.delete('fake:fake')
repository.fallback_data_source.db['fake:fake'] = {'value': True}
entity = await repository.query(fake_entity.id).entity
assert entity == fake_entity.id
assert await repository.memory_data_source.get('fake:fake') == b'1'
@pytest.mark.asyncio
async def test_should_set_memory_after_got_fallback(
repository, fake_entity, mocker
):
repository.memory_data_source.get = asynctest.CoroutineMock(
side_effect=[None]
)
repository.memory_data_source.set = asynctest.CoroutineMock()
repository.fallback_data_source.db['fake:fake'] = {'value': True}
entity = await repository.query(fake_entity.id).entity
assert repository.memory_data_source.get.called
assert repository.memory_data_source.set.call_args_list == [
mocker.call('fake:fake', '1')
]
assert entity == fake_entity.id
|
import constant
import utils
import os
import sys
import subprocess
import json
import argparse
import time
import copy
from optparse import OptionParser
class Collector:
def __init__(self, module):
self.module = module
self.getter_record_file = "results/%s/logs/getter-record" % (module)
self.setter_record_file = "results/%s/logs/setter-record" % (module)
self.param_getter_map = {}
self.param_setter_map = {}
self.param_unset_getter_map = {}
self.params = utils.get_default_params_from_file(self.module)
print("total number of configuration parameters: " + str(len(self.params)))
def parse_getter_record_file(self):
for line in open(self.getter_record_file).readlines():
line = line.strip("\n")
class_pound_method = line.split(" ")[0]
param = line.split(" ")[1]
assert param in self.params, "wrong parameter"
if param not in self.param_getter_map.keys():
self.param_getter_map[param] = set()
self.param_getter_map[param].add(class_pound_method)
def parse_setter_record_file(self):
for line in open(self.setter_record_file).readlines():
line = line.strip("\n")
class_pound_method = line.split(" ")[0]
param = line.split(" ")[1]
assert param in self.params, "wrong parameter"
if param not in self.param_setter_map.keys():
self.param_setter_map[param] = set()
self.param_setter_map[param].add(class_pound_method)
def generate_unset_getter_mapping(self):
for key in self.param_getter_map.keys():
self.param_unset_getter_map[key] = copy.deepcopy(self.param_getter_map[key])
if key in self.param_setter_map.keys():
self.param_unset_getter_map[key].difference_update(self.param_setter_map[key])
if len(self.param_unset_getter_map[key]) == 0:
del self.param_unset_getter_map[key]
def generate_mapping(self):
print ("============================================================")
print ("start reading getter record file")
self.parse_getter_record_file()
print ("finish reading getter record file")
print ("============================================================")
print ("start reading setter record file")
self.parse_setter_record_file()
print ("finish reading setter record file")
print ("============================================================")
print( "size of param_getter_map: " + str(len(self.param_getter_map)))
print( "size of param_setter_map: " + str(len(self.param_setter_map)))
self.generate_unset_getter_mapping()
print( "size of param_unset_getter_map: " + str(len(self.param_unset_getter_map)))
def sanity_check(self):
for key in self.param_unset_getter_map.keys():
assert key in self.params, "error"
if key not in self.param_setter_map.keys():
assert self.param_unset_getter_map[key] == self.param_getter_map[key]
else:
assert self.param_unset_getter_map[key] == self.param_getter_map[key].difference(self.param_setter_map[key])
def output_mapping(self):
for key in self.param_getter_map.keys():
self.param_getter_map[key] = list(self.param_getter_map[key])
for key in self.param_unset_getter_map.keys():
self.param_unset_getter_map[key] = list(self.param_unset_getter_map[key])
for key in self.param_setter_map.keys():
self.param_setter_map[key] = list(self.param_setter_map[key])
json.dump(self.param_getter_map, open("results/%s/param_getter_map.json" % self.module, "w"), indent=2)
json.dump(self.param_unset_getter_map, open("results/%s/param_unset_getter_map.json" % self.module, "w"), indent=2)
json.dump(self.param_setter_map, open("results/%s/param_setter_map.json" % self.module, "w"), indent=2)
if __name__ == "__main__":
s = time.time()
usage = "usage: python3 collector.py project"
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args()
module = args[0]
collector = Collector(module)
collector.generate_mapping()
collector.sanity_check()
collector.output_mapping()
print("total time: {} mins".format((time.time() - s) / 60))
|
from IPython.display import display
import json
import pandas as pd
import requests
import time
NAVERSHOPPING_CATEGORY_URL = "https://search.shopping.naver.com/api/category/"
KAKAOSHOPPING_CATEGORY_URL = "https://shoppinghow.kakao.com/v1.0/category.json"
AUCTION_CATEGORY_URL = "http://script.auction.co.kr/common/headercategoryinfo.js"
ELEVENSTREET_CATEGORY_URL = "https://www.11st.co.kr/main"
HEADERS = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"
def search_category(categories: dict = None, apiaccess: bool = False):
new_categories = []
for category in categories:
if category["catLvl"] == 1:
print("deleting unnecessary keys")
del category["catImg1"], category["catImg2"], category["catImg3"]
if category["isLeaf"] is False:
print("inner categories exists")
if "categories" in category.keys():
print("searching through pre-existing categories")
search_category(category["categories"])
else:
print("searching through api categories")
query = "".join(["?catId=", category["catId"]])
req = requests.get(url="".join([NAVERSHOPPING_CATEGORY_URL, query]))
time.sleep(5)
inner_category = req.json()
search_category(categories=inner_category, apiaccess=True)
else:
if apiaccess is True:
new_categories.append(category)
else:
print("Leaf from no api access")
print(category)
return new_categories
def search_category2(category: dict):
print("current cateogry is ", category)
if category["isLeaf"]:
return category
else:
new_categories = []
if "categories" not in category: # key exists
query = "".join(["?catId=", category["catId"]])
req = requests.get(url="".join([NAVERSHOPPING_CATEGORY_URL, query]))
time.sleep(5)
inner_categories = req.json()
else:
inner_categories = category["categories"]
for inner_category in inner_categories:
new_categories.append(search_category2(inner_category))
category["categories"] = new_categories
return category
def crawl_navershoppingcategory():
headers = {"user-agent": HEADERS}
req = requests.get(url=NAVERSHOPPING_CATEGORY_URL, headers=headers)
categories = req.json()
new_categories = []
for category in categories:
if category["catLvl"] == 1:
del category["catImg1"], category["catImg2"], category["catImg3"]
if category["isLeaf"] is False:
new_categories.append(search_category2(category))
with open("navershoppingcategory.json", "w", encoding="UTF-8") as file:
file.write(json.dumps(new_categories, indent=4, ensure_ascii=False))
def crawl_kakaoshoppingcategory():
headers = {"user-agent": HEADERS}
req = requests.get(url=KAKAOSHOPPING_CATEGORY_URL, headers=headers)
categories = req.json()
print("start searching")
start = time.time()
with open("kakaoshoppingcategory.json", "w", encoding="UTF-8") as file:
file.write(json.dumps(categories, indent=4, ensure_ascii=False))
print("finish searching")
finish = time.time()
print("Took: ", (finish - start))
def run():
print("start searching")
start = time.time()
crawl_navershoppingcategory()
print("finish searching")
finish = time.time()
print("Took: ", (finish - start))
if __name__ == "__main__":
run()
|
"""
Parse raw file content into workable streams.
"""
from __future__ import annotations
from functools import singledispatch
from pathlib import Path
from typing import Final, Iterable, Iterator, List, Optional
from loguru import logger
from music21 import converter, exceptions21, instrument
from sarada import music21
from sarada.notebook import Chord, Musical, Note, Notebook, Rest
supported_extensions: Final = [
".abc",
".mxl",
".rntxt",
".xml",
".musicxml",
".krn",
".midi",
]
def extract_notes(
scores: Iterable[music21.Stream],
) -> Iterator[Iterator[music21.GeneralNote]]:
"""
Extract notes from given file contents.
"""
for score in scores:
partition = instrument.partitionByInstrument(score)
notes: Optional[music21.StreamIterator]
if partition:
notes = partition.parts[0].recurse()
else:
notes = score.flat.notes
if notes:
yield (note for note in notes)
def create_stream(pitches: Iterable[Musical]) -> music21.Stream:
"""
Create stream that may be converted to actual music from pitch list.
"""
notes: List[music21.GeneralNote] = []
for idx, pitch in enumerate(pitches):
note = make_note(pitch)
note.offset = 0.5 * idx
note.storedInstrument = instrument.Piano()
notes.append(note)
return music21.Stream(notes)
@singledispatch
def make_note(musical: Musical) -> music21.GeneralNote:
"""
Convert Musical to music21 equivalent.
"""
raise RuntimeError(f"Dispatch failed for {musical}")
@make_note.register
def make_simple_note(note: Note) -> music21.Note:
m21note = music21.Note(note.pitch, quarterLength=note.duration)
return m21note
@make_note.register
def make_chord(chord: Chord) -> music21.Chord:
m21chord = music21.Chord(chord.pitch, quarterLength=chord.duration)
return m21chord
@make_note.register
def make_rest(rest: Rest) -> music21.Chord:
m21rest = music21.Rest(quarterLength=rest.duration)
return m21rest
def read_scores(path: Path, recursive: bool = False) -> Notebook:
"""
Open file on given path and aggregate them in Notebook instance.
"""
logger.info("Processing files in {path}", path=str(path))
scores = read_files(path, recursive)
notes_source = extract_notes(scores)
notes = Notebook()
for note in notes_source:
notes.add(note)
logger.info("Finished loading files")
return notes
def read_files(path: Path, recursive: bool) -> Iterator[music21.Stream]:
"""
Iterate over content of musical files in provided directory.
"""
for filepath in path.iterdir():
if filepath.is_file() and filepath.suffix in supported_extensions:
logger.debug("Opening file {path}", path=filepath)
try:
score: music21.Stream = converter.parseFile(filepath)
except IOError as e:
logger.warning(
"Error opening file {path}: {e}", path=str(path), e=str(e)
)
continue
except exceptions21.Music21Exception:
logger.warning("Could not parse file {path}", path=str(path))
continue
yield score
elif recursive and filepath.is_dir():
logger.debug("Searching {path}", path=filepath)
yield from read_files(filepath, recursive=True)
else:
logger.debug(
"File {name} omitted due to unsupported extension", name=filepath
)
def store_score(pitches: Iterable[Musical], path: Path) -> None:
"""
Store sequence in midi file.
"""
logger.info("Storing sequence at {path}", path=path)
stream = create_stream(pitches)
logger.debug("Saving file in {path}", path=path)
stream.write("midi", fp=path)
|
from xnas.search_space.mb_layers import *
import numpy as np
def int2list(val, repeat_time=1):
if isinstance(val, list) or isinstance(val, np.ndarray):
return val
elif isinstance(val, tuple):
return list(val)
else:
return [val for _ in range(repeat_time)]
def build_candidate_ops(candidate_ops, in_channels, out_channels, stride, ops_order,
act_func='relu6', use_se=False):
if candidate_ops is None:
raise ValueError('please specify a candidate set')
name2ops = {
'Identity': lambda in_C, out_C, S: IdentityLayer(in_C, out_C, ops_order=ops_order),
'Zero': lambda in_C, out_C, S: ZeroLayer(stride=S),
}
# add MBConv layers
name2ops.update({
'3x3_MBConv1': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 3, S, 1, None, act_func, use_se),
'3x3_MBConv2': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 3, S, 2, None, act_func, use_se),
'3x3_MBConv3': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 3, S, 3, None, act_func, use_se),
'3x3_MBConv4': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 3, S, 4, None, act_func, use_se),
'3x3_MBConv5': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 3, S, 5, None, act_func, use_se),
'3x3_MBConv6': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 3, S, 6, None, act_func, use_se),
#######################################################################################
'5x5_MBConv1': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 5, S, 1, None, act_func, use_se),
'5x5_MBConv2': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 5, S, 2, None, act_func, use_se),
'5x5_MBConv3': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 5, S, 3, None, act_func, use_se),
'5x5_MBConv4': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 5, S, 4, None, act_func, use_se),
'5x5_MBConv5': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 5, S, 5, None, act_func, use_se),
'5x5_MBConv6': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 5, S, 6, None, act_func, use_se),
#######################################################################################
'7x7_MBConv1': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 7, S, 1, None, act_func, use_se),
'7x7_MBConv2': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 7, S, 2, None, act_func, use_se),
'7x7_MBConv3': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 7, S, 3, None, act_func, use_se),
'7x7_MBConv4': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 7, S, 4, None, act_func, use_se),
'7x7_MBConv5': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 7, S, 5, None, act_func, use_se),
'7x7_MBConv6': lambda in_C, out_C, S: MBInvertedConvLayer(in_C, out_C, 7, S, 6, None, act_func, use_se),
})
return [
name2ops[name](in_channels, out_channels, stride) for name in candidate_ops
]
class MobileInvertedResidualBlock(MyNetwork):
def __init__(self, mobile_inverted_conv, shortcut):
super(MobileInvertedResidualBlock, self).__init__()
self.mobile_inverted_conv = mobile_inverted_conv
self.shortcut = shortcut
def forward(self, x):
if self.mobile_inverted_conv.is_zero_layer():
res = x
elif self.shortcut is None or self.shortcut.is_zero_layer():
res = self.mobile_inverted_conv(x)
else:
conv_x = self.mobile_inverted_conv(x)
skip_x = self.shortcut(x)
res = skip_x + conv_x
return res
@property
def module_str(self):
return '(%s, %s)' % (
self.mobile_inverted_conv.module_str, self.shortcut.module_str if self.shortcut is not None else None
)
@property
def config(self):
return {
'name': MobileInvertedResidualBlock.__name__,
'mobile_inverted_conv': self.mobile_inverted_conv.config,
'shortcut': self.shortcut.config if self.shortcut is not None else None,
}
@staticmethod
def build_from_config(config):
mobile_inverted_conv = set_layer_from_config(config['mobile_inverted_conv'])
shortcut = set_layer_from_config(config['shortcut'])
return MobileInvertedResidualBlock(mobile_inverted_conv, shortcut)
def get_flops(self, x):
flops1, conv_x = self.mobile_inverted_conv.get_flops(x)
if self.shortcut:
flops2, _ = self.shortcut.get_flops(x)
else:
flops2 = 0
return flops1 + flops2, self.forward(x)
class MixedEdge(MyModule):
MODE = None # full, two, None, full_v2
def __init__(self, candidate_ops):
super(MixedEdge, self).__init__()
self.candidate_ops = nn.ModuleList(candidate_ops)
self.active_index = [0]
self.inactive_index = None
self.active_vector = np.array([0] * (len(self.candidate_ops)-1) + [1])
@property
def n_choices(self):
return len(self.candidate_ops)
@property
def chosen_index(self):
probs = self.probs_over_ops.data.cpu().numpy()
index = int(np.argmax(probs))
return index, probs[index]
@property
def chosen_op(self):
index, _ = self.chosen_index
return self.candidate_ops[index]
@property
def random_op(self):
index = np.random.choice([_i for _i in range(self.n_choices)], 1)[0]
return self.candidate_ops[index]
def entropy(self, eps=1e-8):
probs = self.probs_over_ops
log_probs = torch.log(probs + eps)
entropy = - torch.sum(torch.mul(probs, log_probs))
return entropy
def is_zero_layer(self):
return self.active_op.is_zero_layer()
@property
def active_op(self):
""" assume only one path is active """
return self.candidate_ops[self.active_index[0]]
def set_chosen_op_active(self):
chosen_idx, _ = self.chosen_index
self.active_index = [chosen_idx]
self.inactive_index = [_i for _i in range(0, chosen_idx)] + \
[_i for _i in range(chosen_idx + 1, self.n_choices)]
""" """
def forward(self, x):
# output = 0
# for i in self.active_index:
# oi = self.candidate_ops[i](x)
# output = output + oi
# only support 1 selection
assert len(self.candidate_ops) == len(self.active_vector)
_x = 0
for i, value in enumerate(self.active_vector):
if value == 1:
_x += self.candidate_ops[i](x)
if 0 < value < 1:
_x += value * self.candidate_ops[i](x)
return _x
@property
def module_str(self):
chosen_index, probs = self.chosen_index
return 'Mix(%s, %.3f)' % (self.candidate_ops[chosen_index].module_str, probs)
@staticmethod
def name():
return 'MixedEdge'
@property
def config(self):
return {
'name': MixedEdge.__name__,
'selection': [i.config for i in self.candidate_ops],
}
@staticmethod
def build_from_config(config):
raise ValueError('not needed')
def get_flops(self, x):
""" Only active paths taken into consideration when calculating FLOPs """
flops = 0
for i in self.active_index:
delta_flop, _ = self.candidate_ops[i].get_flops(x)
flops += delta_flop
return flops, self.forward(x)
|
from pathlib import Path
import io
import os
import numpy as np
import cv2
import hashlib
import urllib
import shutil
import gzip
import tarfile
import zipfile
import warnings
import inspect
from abc import ABCMeta, abstractmethod
from cv2 import IMREAD_COLOR, IMREAD_GRAYSCALE, IMREAD_UNCHANGED
from lxml.etree import Element, ElementTree, SubElement
try:
from PIL import Image
except ImportError:
Image = None
from .handlers import JsonHandler, PickleHandler, YamlHandler
from .misc_util import is_str
from .path_util import check_file_exist, mkdir_or_exist
from .data_util import get_classes
file_handlers = {
"json": JsonHandler(),
"yaml": YamlHandler(),
"yml": YamlHandler(),
"pickle": PickleHandler(),
"pkl": PickleHandler(),
}
supported_backends = ["cv2", "pillow"]
imread_flags = {
"color": IMREAD_COLOR,
"grayscale": IMREAD_GRAYSCALE,
"unchanged": IMREAD_UNCHANGED,
}
imread_backend = "cv2"
def _pillow2array(img, flag="color", channel_order="bgr"):
"""Convert a pillow image to numpy array.
Args:
img (:obj:`PIL.Image.Image`): The image loaded using PIL
flag (str): Flags specifying the color type of a loaded image,
candidates are 'color', 'grayscale' and 'unchanged'.
Default to 'color'.
channel_order (str): The channel order of the output image array,
candidates are 'bgr' and 'rgb'. Default to 'bgr'.
Returns:
np.ndarray: The converted numpy array
"""
channel_order = channel_order.lower()
if channel_order not in ["rgb", "bgr"]:
raise ValueError('channel order must be either "rgb" or "bgr"')
if flag == "unchanged":
array = np.array(img)
if array.ndim >= 3 and array.shape[2] >= 3: # color image
array[:, :, :3] = array[:, :, (2, 1, 0)] # RGB to BGR
else:
# If the image mode is not 'RGB', convert it to 'RGB' first.
if img.mode != "RGB":
if img.mode != "LA":
# Most formats except 'LA' can be directly converted to RGB
img = img.convert("RGB")
else:
# When the mode is 'LA', the default conversion will fill in
# the canvas with black, which sometimes shadows black objects
# in the foreground.
#
# Therefore, a random color (124, 117, 104) is used for canvas
img_rgba = img.convert("RGBA")
img = Image.new("RGB", img_rgba.size, (124, 117, 104))
img.paste(img_rgba, mask=img_rgba.split()[3]) # 3 is alpha
if flag == "color":
array = np.array(img)
if channel_order != "rgb":
array = array[:, :, ::-1] # RGB to BGR
elif flag == "grayscale":
img = img.convert("L")
array = np.array(img)
else:
raise ValueError(
'flag must be "color", "grayscale" or "unchanged", ' f"but got {flag}"
)
return array
def imread(img_or_path, flag="color", channel_order="bgr", backend=None):
"""Read an image.
Args:
img_or_path (ndarray or str or Path): Either a numpy array or str or
pathlib.Path. If it is a numpy array (loaded image), then
it will be returned as is.
flag (str): Flags specifying the color type of a loaded image,
candidates are `color`, `grayscale` and `unchanged`.
Note that the `turbojpeg` backened does not support `unchanged`.
channel_order (str): Order of channel, candidates are `bgr` and `rgb`.
backend (str | None): The image decoding backend type. Options are
`cv2`, `pillow`, `turbojpeg`, `None`. If backend is None, the
global imread_backend specified by ``use_backend()`` will be
used. Default: None.
Returns:
ndarray: Loaded image array.
"""
if backend is None:
backend = imread_backend
if backend not in supported_backends:
raise ValueError(
f"backend: {backend} is not supported. Supported "
"backends are 'cv2', 'turbojpeg', 'pillow'"
)
if isinstance(img_or_path, Path):
img_or_path = str(img_or_path)
if isinstance(img_or_path, np.ndarray):
return img_or_path
elif is_str(img_or_path):
check_file_exist(img_or_path, f"img file does not exist: {img_or_path}")
if backend == "pillow":
img = Image.open(img_or_path)
img = _pillow2array(img, flag, channel_order)
return img
else:
flag = imread_flags[flag] if is_str(flag) else flag
img = cv2.imread(img_or_path, flag)
if flag == IMREAD_COLOR and channel_order == "rgb":
cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img)
return img
else:
raise TypeError(
'"img" must be a numpy array or a str or ' "a pathlib.Path object"
)
def imwrite(img, file_path, params=None, auto_mkdir=True):
"""Write image to file.
Args:
img (ndarray): Image array to be written.
file_path (str): Image file path.
params (None or list): Same as opencv's :func:`imwrite` interface.
auto_mkdir (bool): If the parent folder of `file_path` does not exist,
whether to create it automatically.
Returns:
bool: Successful or not.
"""
if auto_mkdir:
dir_name = os.path.abspath(os.path.dirname(file_path))
mkdir_or_exist(dir_name)
return cv2.imwrite(file_path, img, params)
def imfrombytes(content, flag="color", channel_order="bgr", backend=None):
"""Read an image from bytes.
Args:
content (bytes): Image bytes got from files or other streams.
flag (str): Same as :func:`imread`.
backend (str | None): The image decoding backend type. Options are
`cv2`, `pillow`, `turbojpeg`, `None`. If backend is None, the
global imread_backend specified by ``use_backend()`` will be
used. Default: None.
Returns:
ndarray: Loaded image array.
"""
if backend is None:
backend = imread_backend
if backend not in supported_backends:
raise ValueError(
f"backend: {backend} is not supported. Supported "
"backends are 'cv2', 'pillow'"
)
if backend == "pillow":
buff = io.BytesIO(content)
img = Image.open(buff)
img = _pillow2array(img, flag, channel_order)
else:
img_np = np.frombuffer(content, np.uint8)
flag = imread_flags[flag] if is_str(flag) else flag
img = cv2.imdecode(img_np, flag)
if flag == IMREAD_COLOR and channel_order == "rgb":
cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img)
return img
def file_load(file, file_format=None, **kwargs):
"""Load data from json/yaml/pickle files.
This method provides a unified api for loading data from serialized files.
Args:
file (str or :obj:`Path` or file-like object): Filename or a file-like
object.
file_format (str, optional): If not specified, the file format will be
inferred from the file extension, otherwise use the specified one.
Currently supported formats include "json", "yaml/yml" and
"pickle/pkl".
Returns:
The content from the file.
"""
if isinstance(file, Path):
file = str(file)
if file_format is None and isinstance(file, str):
file_format = file.split(".")[-1]
if file_format not in file_handlers:
raise TypeError(f"Unsupported format: {file_format}")
handler = file_handlers[file_format]
if isinstance(file, str):
obj = handler.load_from_path(file, **kwargs)
elif hasattr(file, "read"):
obj = handler.load_from_fileobj(file, **kwargs)
else:
raise TypeError('"file" must be a filepath str or a file-object')
return obj
def obj_dump(obj, file=None, file_format=None, **kwargs):
"""Dump data to json/yaml/pickle strings or files.
This method provides a unified api for dumping data as strings or to files,
and also supports custom arguments for each file format.
Args:
obj (any): The python object to be dumped.
file (str or :obj:`Path` or file-like object, optional): If not
specified, then the object is dump to a str, otherwise to a file
specified by the filename or file-like object.
file_format (str, optional): Same as :func:`load`.
Returns:
bool: True for success, False otherwise.
"""
if isinstance(file, Path):
file = str(file)
if file_format is None:
if isinstance(file, str):
file_format = file.split(".")[-1]
elif file is None:
raise ValueError("file_format must be specified since file is None")
if file_format not in file_handlers:
raise TypeError(f"Unsupported format: {file_format}")
handler = file_handlers[file_format]
if file is None:
return handler.dump_to_str(obj, **kwargs)
elif isinstance(file, str):
handler.dump_to_path(obj, file, **kwargs)
elif hasattr(file, "write"):
handler.dump_to_fileobj(obj, file, **kwargs)
else:
raise TypeError('"file" must be a filename str or a file-object')
def list_from_file(filename, prefix="", offset=0, max_num=0):
"""Load a text file and parse the content as a list of strings.
Args:
filename (str): Filename.
prefix (str): The prefix to be inserted to the begining of each item.
offset (int): The offset of lines.
max_num (int): The maximum number of lines to be read,
zeros and negatives mean no limitation.
Returns:
list[str]: A list of strings.
"""
cnt = 0
item_list = []
with open(filename, "r") as f:
for _ in range(offset):
f.readline()
for line in f:
if max_num > 0 and cnt >= max_num:
break
item_list.append(prefix + line.rstrip("\n"))
cnt += 1
return item_list
def dict_from_file(filename, key_type=str):
"""Load a text file and parse the content as a dict.
Each line of the text file will be two or more columns splited by
whitespaces or tabs. The first column will be parsed as dict keys, and
the following columns will be parsed as dict values.
Args:
filename(str): Filename.
key_type(type): Type of the dict's keys. str is user by default and
type conversion will be performed if specified.
Returns:
dict: The parsed contents.
"""
mapping = {}
with open(filename, "r") as f:
for line in f:
items = line.rstrip("\n").split()
assert len(items) >= 2
key = key_type(items[0])
val = items[1:] if len(items) > 2 else items[1]
mapping[key] = val
return mapping
def rm_suffix(s, suffix=None):
if suffix is None:
return s[: s.rfind(".")]
else:
return s[: s.rfind(suffix)]
def calculate_md5(fpath, chunk_size=1024 * 1024):
md5 = hashlib.md5()
with open(fpath, "rb") as f:
for chunk in iter(lambda: f.read(chunk_size), b""):
md5.update(chunk)
return md5.hexdigest()
def check_md5(fpath, md5, **kwargs):
return md5 == calculate_md5(fpath, **kwargs)
def check_integrity(fpath, md5=None):
if not os.path.isfile(fpath):
return False
if md5 is None:
return True
return check_md5(fpath, md5)
def download_url_to_file(url, fpath):
with urllib.request.urlopen(url) as resp, open(fpath, "wb") as of:
shutil.copyfileobj(resp, of)
def download_url(url, root, filename=None, md5=None):
"""Download a file from a url and place it in root.
Args:
url (str): URL to download file from.
root (str): Directory to place downloaded file in.
filename (str | None): Name to save the file under.
If filename is None, use the basename of the URL.
md5 (str | None): MD5 checksum of the download.
If md5 is None, download without md5 check.
"""
root = os.path.expanduser(root)
if not filename:
filename = os.path.basename(url)
fpath = os.path.join(root, filename)
os.makedirs(root, exist_ok=True)
if check_integrity(fpath, md5):
print(f"Using downloaded and verified file: {fpath}")
else:
try:
print(f"Downloading {url} to {fpath}")
download_url_to_file(url, fpath)
except (urllib.error.URLError, IOError) as e:
if url[:5] == "https":
url = url.replace("https:", "http:")
print(
"Failed download. Trying https -> http instead."
f" Downloading {url} to {fpath}"
)
download_url_to_file(url, fpath)
else:
raise e
# check integrity of downloaded file
if not check_integrity(fpath, md5):
raise RuntimeError("File not found or corrupted.")
def _is_tarxz(filename):
return filename.endswith(".tar.xz")
def _is_tar(filename):
return filename.endswith(".tar")
def _is_targz(filename):
return filename.endswith(".tar.gz")
def _is_tgz(filename):
return filename.endswith(".tgz")
def _is_gzip(filename):
return filename.endswith(".gz") and not filename.endswith(".tar.gz")
def _is_zip(filename):
return filename.endswith(".zip")
def extract_archive(from_path, to_path=None, remove_finished=False):
if to_path is None:
to_path = os.path.dirname(from_path)
if _is_tar(from_path):
with tarfile.open(from_path, "r") as tar:
tar.extractall(path=to_path)
elif _is_targz(from_path) or _is_tgz(from_path):
with tarfile.open(from_path, "r:gz") as tar:
tar.extractall(path=to_path)
elif _is_tarxz(from_path):
with tarfile.open(from_path, "r:xz") as tar:
tar.extractall(path=to_path)
elif _is_gzip(from_path):
to_path = os.path.join(
to_path, os.path.splitext(os.path.basename(from_path))[0]
)
with open(to_path, "wb") as out_f, gzip.GzipFile(from_path) as zip_f:
out_f.write(zip_f.read())
elif _is_zip(from_path):
with zipfile.ZipFile(from_path, "r") as z:
z.extractall(to_path)
else:
raise ValueError(f"Extraction of {from_path} not supported")
if remove_finished:
os.remove(from_path)
def download_and_extract_archive(
url,
download_root,
extract_root=None,
filename=None,
md5=None,
remove_finished=False,
):
download_root = os.path.expanduser(download_root)
if extract_root is None:
extract_root = download_root
if not filename:
filename = os.path.basename(url)
download_url(url, download_root, filename, md5)
archive = os.path.join(download_root, filename)
print(f"Extracting {archive} to {extract_root}")
extract_archive(archive, extract_root, remove_finished)
def write_det_xml(out_file, width, height, bboxes, labels, dataset_name):
node_root = Element("annotation")
node_folder = SubElement(node_root, "folder")
node_folder.text = "images"
node_filename = SubElement(node_root, "filename")
node_filename.text = os.path.basename(out_file)[:-4] + ".jpg"
node_size = SubElement(node_root, "size")
node_width = SubElement(node_size, "width")
node_width.text = str(width)
node_height = SubElement(node_size, "height")
node_height.text = str(height)
class_names = get_classes(dataset_name)
for i in range(len(bboxes)):
node_object = SubElement(node_root, "object")
node_name = SubElement(node_object, "name")
node_name.text = class_names[labels[i]]
node_truncated = SubElement(node_object, "truncated")
node_truncated.text = "0"
node_difficult = SubElement(node_object, "difficult")
node_difficult.text = "0"
node_bndbox = SubElement(node_object, "bndbox")
node_xmin = SubElement(node_bndbox, "xmin")
node_xmin.text = str(bboxes[i][0])
node_ymin = SubElement(node_bndbox, "ymin")
node_ymin.text = str(bboxes[i][1])
node_xmax = SubElement(node_bndbox, "xmax")
node_xmax.text = str(bboxes[i][2])
node_ymax = SubElement(node_bndbox, "ymax")
node_ymax.text = str(bboxes[i][3])
# xml_str = tostring(node_root, pretty_print=True)
tree = ElementTree(node_root)
tree.write(out_file, pretty_print=True, xml_declaration=False, encoding="utf-8")
class BaseStorageBackend(metaclass=ABCMeta):
"""Abstract class of storage backends.
All backends need to implement two apis: ``get()`` and ``get_text()``.
``get()`` reads the file as a byte stream and ``get_text()`` reads the file
as texts.
"""
@abstractmethod
def get(self, filepath):
pass
@abstractmethod
def get_text(self, filepath):
pass
class CephBackend(BaseStorageBackend):
"""Ceph storage backend.
Args:
path_mapping (dict|None): path mapping dict from local path to Petrel
path. When ``path_mapping={'src': 'dst'}``, ``src`` in ``filepath``
will be replaced by ``dst``. Default: None.
"""
def __init__(self, path_mapping=None):
try:
import ceph
warnings.warn("Ceph is deprecate in favor of Petrel.")
except ImportError:
raise ImportError("Please install ceph to enable CephBackend.")
self._client = ceph.S3Client()
assert isinstance(path_mapping, dict) or path_mapping is None
self.path_mapping = path_mapping
def get(self, filepath):
filepath = str(filepath)
if self.path_mapping is not None:
for k, v in self.path_mapping.items():
filepath = filepath.replace(k, v)
value = self._client.Get(filepath)
value_buf = memoryview(value)
return value_buf
def get_text(self, filepath):
raise NotImplementedError
class PetrelBackend(BaseStorageBackend):
"""Petrel storage backend (for internal use).
Args:
path_mapping (dict|None): path mapping dict from local path to Petrel
path. When `path_mapping={'src': 'dst'}`, `src` in `filepath` will
be replaced by `dst`. Default: None.
enable_mc (bool): whether to enable memcached support. Default: True.
"""
def __init__(self, path_mapping=None, enable_mc=True):
try:
from petrel_client import client
except ImportError:
raise ImportError(
"Please install petrel_client to enable " "PetrelBackend."
)
self._client = client.Client(enable_mc=enable_mc)
assert isinstance(path_mapping, dict) or path_mapping is None
self.path_mapping = path_mapping
def get(self, filepath):
filepath = str(filepath)
if self.path_mapping is not None:
for k, v in self.path_mapping.items():
filepath = filepath.replace(k, v)
value = self._client.Get(filepath)
value_buf = memoryview(value)
return value_buf
def get_text(self, filepath):
raise NotImplementedError
class MemcachedBackend(BaseStorageBackend):
"""Memcached storage backend.
Attributes:
server_list_cfg (str): Config file for memcached server list.
client_cfg (str): Config file for memcached client.
sys_path (str | None): Additional path to be appended to `sys.path`.
Default: None.
"""
def __init__(self, server_list_cfg, client_cfg, sys_path=None):
if sys_path is not None:
import sys
sys.path.append(sys_path)
try:
import mc
except ImportError:
raise ImportError("Please install memcached to enable MemcachedBackend.")
self.server_list_cfg = server_list_cfg
self.client_cfg = client_cfg
self._client = mc.MemcachedClient.GetInstance(
self.server_list_cfg, self.client_cfg
)
# mc.pyvector servers as a point which points to a memory cache
self._mc_buffer = mc.pyvector()
def get(self, filepath):
try:
import mc
except ImportError:
raise ImportError("Please install memcached to enable MemcachedBackend.")
filepath = str(filepath)
self._client.Get(filepath, self._mc_buffer)
value_buf = mc.ConvertBuffer(self._mc_buffer)
return value_buf
def get_text(self, filepath):
raise NotImplementedError
class LmdbBackend(BaseStorageBackend):
"""Lmdb storage backend.
Args:
db_path (str): Lmdb database path.
readonly (bool, optional): Lmdb environment parameter. If True,
disallow any write operations. Default: True.
lock (bool, optional): Lmdb environment parameter. If False, when
concurrent access occurs, do not lock the database. Default: False.
readahead (bool, optional): Lmdb environment parameter. If False,
disable the OS filesystem readahead mechanism, which may improve
random read performance when a database is larger than RAM.
Default: False.
Attributes:
db_path (str): Lmdb database path.
"""
def __init__(self, db_path, readonly=True, lock=False, readahead=False, **kwargs):
try:
import lmdb
except ImportError:
raise ImportError("Please install lmdb to enable LmdbBackend.")
self.db_path = str(db_path)
self._client = lmdb.open(
self.db_path, readonly=readonly, lock=lock, readahead=readahead, **kwargs
)
def get(self, filepath):
"""Get values according to the filepath.
Args:
filepath (str | obj:`Path`): Here, filepath is the lmdb key.
"""
filepath = str(filepath)
with self._client.begin(write=False) as txn:
value_buf = txn.get(filepath.encode("ascii"))
return value_buf
def get_text(self, filepath):
raise NotImplementedError
class HardDiskBackend(BaseStorageBackend):
"""Raw hard disks storage backend."""
def get(self, filepath):
filepath = str(filepath)
with open(filepath, "rb") as f:
value_buf = f.read()
return value_buf
def get_text(self, filepath):
filepath = str(filepath)
with open(filepath, "r") as f:
value_buf = f.read()
return value_buf
class FileClient:
"""A general file client to access files in different backend.
The client loads a file or text in a specified backend from its path
and return it as a binary file. it can also register other backend
accessor with a given name and backend class.
Attributes:
backend (str): The storage backend type. Options are "disk", "ceph",
"memcached" and "lmdb".
client (:obj:`BaseStorageBackend`): The backend object.
"""
_backends = {
"disk": HardDiskBackend,
"ceph": CephBackend,
"memcached": MemcachedBackend,
"lmdb": LmdbBackend,
"petrel": PetrelBackend,
}
def __init__(self, backend="disk", **kwargs):
if backend not in self._backends:
raise ValueError(
f"Backend {backend} is not supported. Currently supported ones"
f" are {list(self._backends.keys())}"
)
self.backend = backend
self.client = self._backends[backend](**kwargs)
@classmethod
def _register_backend(cls, name, backend, force=False):
if not isinstance(name, str):
raise TypeError(
"the backend name should be a string, " f"but got {type(name)}"
)
if not inspect.isclass(backend):
raise TypeError(f"backend should be a class but got {type(backend)}")
if not issubclass(backend, BaseStorageBackend):
raise TypeError(
f"backend {backend} is not a subclass of BaseStorageBackend"
)
if not force and name in cls._backends:
raise KeyError(
f"{name} is already registered as a storage backend, "
'add "force=True" if you want to override it'
)
cls._backends[name] = backend
@classmethod
def register_backend(cls, name, backend=None, force=False):
"""Register a backend to FileClient.
This method can be used as a normal class method or a decorator.
.. code-block:: python
class NewBackend(BaseStorageBackend):
def get(self, filepath):
return filepath
def get_text(self, filepath):
return filepath
FileClient.register_backend('new', NewBackend)
or
.. code-block:: python
@FileClient.register_backend('new')
class NewBackend(BaseStorageBackend):
def get(self, filepath):
return filepath
def get_text(self, filepath):
return filepath
Args:
name (str): The name of the registered backend.
backend (class, optional): The backend class to be registered,
which must be a subclass of :class:`BaseStorageBackend`.
When this method is used as a decorator, backend is None.
Defaults to None.
force (bool, optional): Whether to override the backend if the name
has already been registered. Defaults to False.
"""
if backend is not None:
cls._register_backend(name, backend, force=force)
return
def _register(backend_cls):
cls._register_backend(name, backend_cls, force=force)
return backend_cls
return _register
def get(self, filepath):
return self.client.get(filepath)
def get_text(self, filepath):
return self.client.get_text(filepath)
|
"""Determine quadcopter's pose using a pair of Aruco fiducial makers."""
__author__ = "<NAME>"
__copyright__ = "Copyright 2019, <NAME>"
__credits__ = ["<NAME>"]
__license__ = "BSD 3-Clause License"
__version__ = "1.0.0"
__status__ = "Development"
import math
import numpy as np
import cv2
from cv2 import aruco
class Pose:
"""Determine quadcopter's pose using a pair of Aruco fiducial makers."""
# Set up aruco markers as class variables.
aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
aruco_params = aruco.DetectorParameters_create()
# Aruco target parameters.
target_size = 12.3 # Aruco target size in cm.
target_dist = 32.2 # Distance between center of targets in cm.
# 'target_objp' defined the points around the two markers. We
# start at the upper left hand point of the left hand marker and
# go clockwise. Then we do the upper left hand point of the right
# marker and go clockwise. Everthing is positioned relative to the
# center of the gate we want to transition through.
max_dx = (target_size + target_dist)/2
min_dx = max_dx - target_size
dy = target_size/2
target_objp = np.array([[-max_dx, -dy, 0],
[-min_dx, -dy, 0],
[-min_dx, dy, 0],
[-max_dx, dy, 0],
[min_dx, -dy, 0],
[max_dx, -dy, 0],
[max_dx, dy, 0],
[min_dx, dy, 0]], np.float32)
# Set up camera calibration data as class variables.
with np.load('calibration.npz') as x:
camera_matrix = x['cameraMatrix']
dist_coeffs = x['distCoeffs']
def __init__(self):
"""Initialize pose with image"""
self.frame = None # Input image frame.
self.gray = None # Undisorted gray scale image to process.
self.corners = None # Corners of detected fiducial markers.
self.ids = None # IDs of detected fiducial markers.
self.rvecs = None # Rotation vector of detected markers.
self.tvecs = None # Translation vector of detected markers.
self.found = False # True if detected and processed both markers.
self.runtime = 0 # Runtime of last solve.
self.status = None # Status information.
def solve(self, frame, expected_id):
"""Solve for quadcopter pose"""
e1 = cv2.getTickCount()
self.frame = frame
self.gray = create_gray_frame(frame)
self.corners, self.ids = detect_markers(self.gray, expected_id)
if self.corners is not None and len(self.corners) == 2:
self.found, self.rvecs, self.tvecs = position_markers(self.corners)
else:
self.found = False
self.rvecs = None
self.tvecs = None
self.runtime = (cv2.getTickCount() - e1)/cv2.getTickFrequency()*1000
return self.found
def display_results(self):
"""Create image and display results on it"""
result = cv2.cvtColor(self.gray, cv2.COLOR_GRAY2BGR)
if self.corners is None:
return result
# Draw the fiduals found.
result = aruco.drawDetectedMarkers(result, self.corners, self.ids)
if self.found:
seglen = 8
axis = np.float32([
[0, 0, 0], # Center point
[seglen, 0, 0], # X axis
[0, seglen, 0], # Y axis
[0, 0, -seglen] # Z axis
]).reshape(-1, 3)
imgpts, _ = cv2.projectPoints(axis, self.rvecs, self.tvecs,
Pose.camera_matrix, Pose.dist_coeffs)
result = draw_axis(result, imgpts)
self.add_status(result)
return result
def height(self):
if self.found:
return self.tvecs[1][0]
else:
return 0.0
def add_status(self, result):
"""Display status information on the result image"""
rad2deg = 180/math.pi
color = (200, 255, 255)
if self.found:
color = (0, 255, 255)
self.status = (self.tvecs[0][0],
self.tvecs[1][0],
self.tvecs[2][0],
self.rvecs[0][0]*rad2deg,
self.rvecs[1][0]*rad2deg,
self.rvecs[2][0]*rad2deg,
segment_length(self.tvecs[0][0],
self.tvecs[1][0],
self.tvecs[2][0]))
s = self.status
msg = ("%.1f ms (%.1f, %.1f, %.1f) "+
"r:(%.1f, %.1f, %.1f) len:%.1f") % (self.runtime,
s[0], s[1], s[2],
s[3], s[4], s[5], s[6])
cv2.putText(result, msg, (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.6,
color, lineType=cv2.LINE_AA)
def create_gray_frame(frame):
"""Create and return an undistorted grayscale image"""
h, w = frame.shape[:2]
new_matrix, _ = cv2.getOptimalNewCameraMatrix(Pose.camera_matrix,
Pose.dist_coeffs,
(w, h), 1, (w, h))
fixed = cv2.undistort(frame, Pose.camera_matrix, Pose.dist_coeffs,
None, new_matrix)
return cv2.cvtColor(fixed, cv2.COLOR_BGR2GRAY)
def detect_markers(gray, expected_id):
"""Detect and return corners with the correct ID."""
d_corners, d_ids, _ = aruco.detectMarkers(gray,
Pose.aruco_dict,
parameters=Pose.aruco_params,
cameraMatrix=Pose.camera_matrix)
# Only keep the corners from the expected IDs.
ids = np.array([])
corners = []
for i in range(len(d_corners)):
if d_ids[i][0] == expected_id:
np.append(ids, d_ids[i])
corners.append(d_corners[i])
return corners, ids
def draw_axis(img, imgpts):
"""Draw an x, y, z axis on image."""
corner = tuple(imgpts[0].ravel())
img = cv2.line(img, corner, tuple(imgpts[1].ravel()), (255, 0, 0), 3)
img = cv2.line(img, corner, tuple(imgpts[2].ravel()), (0, 255, 0), 3)
img = cv2.line(img, corner, tuple(imgpts[3].ravel()), (0, 0, 255), 3)
return img
def segment_length(x, y, z):
"""Return the length of the segment."""
return math.sqrt(x*x+y*y+z*z)
def position_markers(corners):
"""Take 2D points and apply against 3D model of fiducial markers."""
p1 = np.array(corners[0][0], np.float32)
p2 = np.array(corners[1][0], np.float32)
if p1[0][0] > p2[0][0]:
p1, p2 = p2, p1
all_corners = np.concatenate((p1, p2), axis=0)
return cv2.solvePnP(Pose.target_objp, all_corners,
Pose.camera_matrix, Pose.dist_coeffs)
|
<gh_stars>0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pickle
from sklearn.linear_model import LinearRegression, LassoCV, ElasticNetCV, RidgeCV
from scipy.stats.stats import pearsonr
from scipy.stats import truncnorm
from scipy import stats
from sklearn.metrics import roc_curve, auc
from matplotlib.gridspec import GridSpec
import seaborn as sns
def define_model(compile_model = False):
model_name = 'model.pkl'
if compile_model:
code= """
data {
int<lower=1> N; // number of cells
int<lower=1> M; // number of inputs
int<lower=0> X[M,N]; // input matrix
int<lower=0> y[N]; // output vector
real<lower=0> beta0_std; // std for beta0
real<lower=0> beta_std; // std for beta
real log_mux_mean;
real<lower=0> log_mux_std;// std for mux
real<lower=0> alpha_std; // std for alpha
vector[N] log_c; // logarithmic normalization constants
}
parameters {
matrix[N,M] log_CX; // log-parameters for Poisson inputs
vector[N] log_Cy;
vector[M] log_mux;
real beta0;
vector[M] beta;
real<lower=0> alpha;
}
model {
log_mux ~ normal(log_mux_mean, log_mux_std);
beta0 ~ normal(0, beta0_std);
beta ~ normal(0, beta_std);
alpha ~ normal(0, alpha_std); // half-normal prior
// prior for log-parameters of Poisson inputs
to_vector(log_CX) ~ normal(to_vector(rep_matrix(log_mux',N)) - 0.5 * log(1 + alpha),sqrt(log(1 + alpha)));
log_Cy ~ normal(log_CX*beta + beta0, sqrt(log(1 + alpha)));
// likelihood
y ~ poisson_log(log_Cy + log_c);
to_array_1d(X) ~ poisson_log(to_vector(log_CX + rep_matrix(log_c, M) ));
}
"""
from pystan import StanModel
# compile
stan_model = StanModel(model_code=code)
# save the model to the file
with open(model_name, 'wb') as f:
pickle.dump(stan_model, f)
else:
stan_model = pickle.load(open(model_name, 'rb'))
return stan_model
def run_inference(X,y,prior_params,norm_consts,stan_model,N_iter = 500,N_chains = 4):
N, M = X.shape
# inference
dat = {'N': N,'M':M,'X': X.T,'y': y,'log_c': np.log(norm_consts),
'beta0_std': prior_params['beta0_prior_std'],'beta_std': prior_params['beta_prior_std'],
'log_mux_mean': prior_params['log_mux_prior_mean'],'log_mux_std': prior_params['log_mux_prior_std'],
'alpha_std': prior_params['alpha_prior_std']}
with suppress_stdout_stderr():
fit = stan_model.sampling(data=dat, iter=N_iter, chains=N_chains)
return fit
def fit2table(fit,name,M):
result_p1 = pd.DataFrame(index=range(M),data={
'SCHiRM'+name+'p' : compute_prob_score(fit['beta']),
'SCHiRM'+name+'pm' : fit['beta'].mean(axis=0),
'beta_std'+name : fit['beta'].std(axis=0),
'mux_mean'+name : np.exp(fit['log_mux']).mean(axis=0),
'mux_std'+name : np.exp(fit['log_mux']).std(axis=0)})
result_p2 = pd.DataFrame(index=np.array([0]),data={
'beta0_mean'+name: fit['beta0'].mean(),
'beta0_std'+name : fit['beta0'].std(),
'alpha_mean'+name: fit['alpha'].mean(),
'alpha_std'+name : fit['alpha'].std() })
return result_p1, result_p2
def run_standard_reg(X,y,norm_consts):
N, M = X.shape
# normalize and log-transform
logXn = np.log(1+(X/norm_consts[:,None]))
logyn = np.log(1+(y/norm_consts))
# OLS
ols = LinearRegression()
ols.fit(logXn,logyn)
# LASSO
clf = LassoCV()
clf.fit(logXn,logyn)
# ELASTIC NET
regr = ElasticNetCV()
regr.fit(logXn,logyn)
# RIDGE REGRESSION
ridr = RidgeCV()
ridr.fit(logXn,logyn)
# correlation
r = np.zeros(M)
for i in range(M):
r[i] = pearsonr(logXn[:,i],logyn)[0]
# collect
result_p1 = pd.DataFrame(data={
'OLS' : ols.coef_,
'LASSO' : clf.coef_,
'ENET' : regr.coef_,
'RIDGE' : ridr.coef_,
'PCC' : r})
result_p2 = pd.DataFrame(index = np.array([0]),data={
'beta0_ols': ols.intercept_,
'beta0_las': clf.intercept_,
'beta0_ene': regr.intercept_,
'beta0_rid': ridr.intercept_})
return result_p1, result_p2
def sim_truncnormal_dist(loc,scale,lb,ub,N):
a, b = (lb - loc) / scale, (ub - loc) / scale
return truncnorm.rvs(a, b, loc, scale, size=N)
def sim_indep_data(mu,alpha,norm_consts,N):
# mu is an M-vector containing the means of the log-normal distributions
# N is the number of cells
a = np.log(mu) - 0.5*np.log(1 + alpha) # mean in the log-scale
b = np.log(1 + alpha) # variance in the log-scale
log_CX = np.random.multivariate_normal(a, b*np.eye(len(mu)), size=N)
X = np.random.poisson(np.exp(log_CX)*norm_consts[:,None])
return X, log_CX
def sim_beta(M,bounds,Mact):
beta0 = np.random.uniform(bounds['beta0'][0],bounds['beta0'][1],1)
beta = np.zeros(M)
if Mact == None:
if M%2 == 0:
Mact = int(M/2)
else:
Mact = int(np.ceil(M/2)) - np.random.randint(2)
# simulate values for beta and the corresponding output
beta[0:Mact] = np.random.uniform(bounds['beta'][0],bounds['beta'][1],Mact)
return beta0, beta
def sim_output_data(log_CX,norm_consts,alpha,beta0,beta,N):
log_Cy = beta0 + np.dot(log_CX,beta) + np.random.normal(0, np.sqrt(np.log(1+alpha)), N)
y = np.random.poisson(np.exp(log_Cy)*norm_consts)
return y, log_Cy
def compute_prob_score(samples):
N_samp = samples.shape[0]
pos_prob = np.sum(samples > 0,axis=0)/N_samp
neg_prob = np.sum(samples < 0,axis=0)/N_samp
return np.maximum(pos_prob,neg_prob)
def estimate_normconsts(X):
tot_exp = np.sum(X,axis=1)
return len(tot_exp)*tot_exp/np.sum(tot_exp)
def compute_norm_constants_and_mean_expression_prior(df,lb,ub,illust = False):
# estimate normalization constants
c = estimate_normconsts(df.as_matrix())
c_mean = np.round(np.mean(np.log(c)),2)
c_std = np.round(np.std(np.log(c)),2)
# remove the genes which have zero expression in all cells
df = df.iloc[:,df.sum().as_matrix()>0]
# compute average expression of each gene
m = df.mean().as_matrix()
# fit a normal distribution to the logarithmic means (full data, only zeros removed)
m_mean = np.round(np.mean(np.log(m)),2)
m_std = np.round(np.std(np.log(m)),2)
# visualize
if illust:
plt.subplot(2,2,1)
plt.hist(c,density=True)
plt.xlabel('Norm. constant')
plt.subplot(2,2,2)
plt.hist(np.log(c),density=True)
x = np.linspace(np.min(np.log(c)), -np.min(np.log(c)), 100)
pdf = stats.norm.pdf(x,loc=c_mean,scale=c_std)
plt.plot(x, pdf, label="PDF")
plt.xlabel('log(Norm. constant)')
plt.title('mean = '+str(c_mean)+', std = '+str(c_std))
plt.subplot(2,2,3)
plt.hist(np.log(m),density=True)
x = np.linspace(-np.max(np.log(m)), np.max(np.log(m)), 100)
pdf = stats.norm.pdf(x,loc=m_mean,scale=m_std)
plt.plot(x, pdf, label="PDF")
plt.plot([lb,lb],[0,np.max(pdf)], '--k')
plt.plot([ub,ub],[0,np.max(pdf)], '--k')
plt.xlabel('log(Aver. expression)')
plt.title('mean = '+str(m_mean)+', std = '+str(m_std))
return df, c, m_mean, m_std
def compute_jittered_norm_constants(m_mean,m_std,c,N,alpha,Mtot = 5000):
# simulate data to generate realistically jittered estimates of norm. constants
D, log_CD = sim_indep_data(np.exp(np.random.normal(m_mean,m_std,size=Mtot)),alpha,c,N)
# estimate normalization constants from sim. data
return estimate_normconsts(D)
def illust_convergence_diag(rhat,fig_name=None):
fig = plt.figure(figsize=(8,4))
plt.subplot(1,2,1)
plt.hist(rhat.flatten())
plt.xlabel('Rhat')
plt.subplot(1,2,2)
plt.imshow(rhat,cmap=plt.cm.coolwarm)
plt.colorbar()
plt.xlabel('Rhat')
fig.tight_layout()
if fig_name != None:
fig.savefig('./figs/'+fig_name+'.pdf', format='pdf', dpi=1200)
def roc_auc_comparison(df,names = ['SCHiRMp','SCHiRMpm',
'OLS', 'LASSO','ENET','RIDGE','PCC'],fig_name=None):
th = 0
y_true = np.abs(df['beta_true'].as_matrix()) > th
# compute and plor ROC/AUC
AUC = np.array([])
for name in names:
score = np.abs(df[name].as_matrix())
temp = roc_analysis(y_true, score, name, illust = True)
AUC = np.append(AUC,temp)
plt.legend()
# plot AUCs
fig, ax = plt.subplots()
y_pos = np.arange(len(names))
ax.barh(y_pos, AUC, align='center', color='green', ecolor='black')
ax.set_yticks(y_pos)
ax.set_yticklabels(names)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel('AUC')
if fig_name != None:
fig.savefig('./figs/'+fig_name+'.pdf', format='pdf', dpi=1200)
def roc_and_score_dists(df,names = ['SCHiRMp','SCHiRMpm',
'OLS', 'LASSO','ENET','RIDGE','PCC'],fig_name=None):
th = 0
y_true = np.abs(df['beta_true'].as_matrix()) > th
n_rows = 2
fig = plt.figure(figsize=(2*len(names),4))
# compute and plot ROC curves
for i, name in enumerate(names):
# roc curves
plt.subplot(n_rows,len(names),i+1)
score = np.abs(df[name].as_matrix())
roc_analysis(y_true, score, name, illust = True, showxy_label = (i==0))
plt.title(name)
# pos./neg. score distributions
plt.subplot(n_rows,len(names),i+1+len(names))
ind = np.abs(y_true) > th
ind_neq = np.abs(y_true) <= th
plt.hist(score[ind],label='Pos.')
plt.hist(score[ind_neq],alpha=0.5,label='Neg.')
if i == 0:
plt.xlabel('Score')
plt.ylabel('Frequency')
plt.legend()
fig.tight_layout()
# if figure name is given, save the image in .svg format
if fig_name != None:
fig.savefig('./figs/'+fig_name+'.pdf', format='pdf', dpi=1200)
def param_estimates_vs_true_values(df1,df2,
names1 = ['SCHiRMpm', 'OLS', 'LASSO','ENET','RIDGE'],
names2 = ['beta0_mean','beta0_ols', 'beta0_las', 'beta0_ene', 'beta0_rid'],fig_name=None):
n_rows = 4
fig = plt.figure(figsize=(2*len(names1),8))
# true betas vs est
for i, name in enumerate(names1):
plt.subplot(n_rows,len(names1),i+1)
plt.plot([-1,1],[-1,1],'k')
plt.scatter(df1['beta_true'].as_matrix(),df1[name].as_matrix(),s = 0.2)
plt.title(name)
if i == 0:
plt.xlabel('True $\\beta$')
plt.ylabel('Est. $\\beta$')
# true beta0 vs est
for i, name in enumerate(names2):
plt.subplot(n_rows,len(names1),i+1+len(names1))
plt.plot([-1,1],[-1,1],'k')
plt.scatter(df2['beta0_true'].as_matrix(),df2[name].as_matrix(),s = 0.2)
if i == 0:
plt.xlabel('True $\\beta_0$')
plt.ylabel('Est. $\\beta_0$')
# true mu vs est
plt.subplot(n_rows,len(names1),1+2*len(names1))
plt.plot([0,100],[0,100],'k')
plt.scatter(df1['mux_true'].as_matrix(),df1['mux_mean'].as_matrix(),s = 0.6)
plt.xlabel('True $\mu$')
plt.ylabel('Est. $\mu$')
# alpha
plt.subplot(n_rows,len(names1),1+3*len(names1))
plt.hist(df2['alpha_mean'].as_matrix())
plt.xlabel('$\\alpha$')
plt.ylabel('Freq.')
fig.tight_layout()
if fig_name != None:
fig.savefig('./figs/'+fig_name+'.pdf', format='pdf', dpi=1200)
def roc_analysis(y_true, score, lab, illust = False, showxy_label = True):
fpr, tpr, th = roc_curve(y_true, score, pos_label=True)
AUC = auc(fpr, tpr)
if illust:
plt.plot(fpr, tpr,label = lab)
if showxy_label:
plt.xlabel('FPR')
plt.ylabel('TPR')
return AUC
def illust_posterior_violin(S,var_name):
M = S.shape[1]
names = []
for i in range(1,M+1):
var_name_ind = '$\\' + var_name + '_' + str(i) + '$'
names.append(var_name_ind)
df = pd.DataFrame(S,columns=names)
df = df.melt(var_name='Parameter', value_name='Value')
#plt.figure()
sns.set_style("whitegrid")
sns.violinplot(x="Parameter", y="Value", data=df)
def illust_posterior_kde_hist(s,var_name):
sns.distplot(s)
plt.xlabel(var_name)
plt.ylabel('Density')
def illust_post_summary_A(fit, M, true_params=None):
fig = plt.figure(figsize=(6,6))
MS = 12
thickness = 2 # horizontal line thickness
ccc = 'r' # horizontal line color
gs = GridSpec(4, 2)
plt.subplot(gs[2,0])
illust_posterior_kde_hist(fit['beta0'],'$\\beta_0$')
if true_params != None:
beta0 = true_params['beta0']
plt.plot(beta0,0,'|', mew=thickness, ms=MS, color=ccc)
#plt.plot([beta0,beta0],[0,0.65],color=ccc)
plt.subplot(gs[2,1])
illust_posterior_kde_hist(fit['alpha'],'$\\alpha$')
if true_params != None:
alpha = true_params['alpha']
plt.plot(alpha,0,'|', mew=thickness, ms=MS, color=ccc)
#plt.plot([alpha,alpha],[0,15],color=ccc)
plt.subplot(gs[0:2,0])
illust_posterior_violin(fit['beta'],'beta')
if true_params != None:
beta = true_params['beta']
plt.plot(beta,'_', mew=thickness, ms=MS, color=ccc)
plt.subplot(gs[0:2,1])
illust_posterior_violin(np.exp(fit['log_mux']),'mu')
if true_params != None:
mux_true = true_params['mux_true']
plt.plot(mux_true,'_', mew=thickness, ms=MS, color=ccc)
plt.subplot(gs[3,0])
score = np.abs(fit['beta'].mean(axis=0))
plt.stem(range(1,M+1),score)
plt.xticks(range(1,M+1))
plt.xlabel('Input index')
plt.ylabel('Post. mean score')
plt.subplot(gs[3,1])
score = compute_prob_score(fit['beta'])
plt.stem(range(1,M+1),(score-0.5)/0.5)
plt.xticks(range(1,M+1))
plt.xlabel('Input index')
plt.ylabel('2 x Prob. score - 1')
fig.tight_layout()
# from https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions
import os
class suppress_stdout_stderr(object):
'''
A context manager for doing a "deep suppression" of stdout and stderr in
Python, i.e. will suppress all print, even if the print originates in a
compiled C/Fortran sub-function.
This will not suppress raised exceptions, since exceptions are printed
to stderr just before a script exits, and after the context manager has
exited (at least, I think that is why it lets exceptions through).
'''
def __init__(self):
# Open a pair of null files
self.null_fds = [os.open(os.devnull, os.O_RDWR) for x in range(2)]
# Save the actual stdout (1) and stderr (2) file descriptors.
self.save_fds = [os.dup(1), os.dup(2)]
def __enter__(self):
# Assign the null pointers to stdout and stderr.
os.dup2(self.null_fds[0], 1)
os.dup2(self.null_fds[1], 2)
def __exit__(self, *_):
# Re-assign the real stdout/stderr back to (1) and (2)
os.dup2(self.save_fds[0], 1)
os.dup2(self.save_fds[1], 2)
# Close the null files
for fd in self.null_fds + self.save_fds:
os.close(fd)
|
<reponame>grossmann-group/pyomo-MINLP-benchmarking
# MINLP written by GAMS Convert at 05/15/20 00:50:53
#
# Equation counts
# Total E G L N X C B
# 3081 447 0 2634 0 0 0 0
#
# Variable counts
# x b i s1s s2s sc si
# Total cont binary integer sos1 sos2 scont sint
# 1999 1537 462 0 0 0 0 0
# FX 0 0 0 0 0 0 0 0
#
# Nonzero counts
# Total const NL DLL
# 18737 18731 6 0
#
# Reformulation has removed 1 variable and 1 equation
from pyomo.environ import *
model = m = ConcreteModel()
m.x2 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x3 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x4 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x5 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x6 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x7 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x8 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x9 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x10 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x11 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x12 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x13 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x14 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x15 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x16 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x17 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x18 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x19 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x20 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x21 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x22 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x23 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x24 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x25 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x26 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x27 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x28 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x29 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x30 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x31 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x32 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x33 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x34 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x35 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x36 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x37 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x38 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x39 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x40 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x41 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x42 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x43 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x44 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x45 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x46 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x47 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x48 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x49 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x50 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x51 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x52 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x53 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x54 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x55 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x56 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x57 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x58 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x59 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x60 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x61 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x62 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x63 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x64 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x65 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x66 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x67 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x68 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x69 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x70 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x71 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x72 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x73 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x74 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x75 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x76 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x77 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x78 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x79 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x80 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x81 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x82 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x83 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x84 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x85 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x86 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x87 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x88 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x89 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x90 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x91 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x92 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x93 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x94 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x95 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x96 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x97 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x98 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x99 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x100 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x101 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x102 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x103 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x104 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x105 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x106 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x107 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x108 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x109 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x110 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x111 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x112 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x113 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x114 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x115 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x116 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x117 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x118 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x119 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x120 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x121 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x122 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x123 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x124 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x125 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x126 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x127 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x128 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x129 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x130 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x131 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x132 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x133 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x134 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x135 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x136 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x137 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x138 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x139 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x140 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x141 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x142 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x143 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x144 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x145 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x146 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x147 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x148 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x149 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x150 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x151 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x152 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x153 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x154 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x155 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x156 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x157 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x158 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x159 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x160 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x161 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x162 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x163 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x164 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x165 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x166 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x167 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x168 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x169 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x170 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x171 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x172 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x173 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x174 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x175 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x176 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x177 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x178 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x179 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x180 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x181 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x182 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x183 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x184 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x185 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x186 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x187 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x188 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x189 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x190 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x191 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x192 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x193 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x194 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x195 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x196 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x197 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x198 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x199 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x200 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x201 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x202 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x203 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x204 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x205 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x206 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x207 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x208 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x209 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x210 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x211 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x212 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x213 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x214 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x215 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x216 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x217 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x218 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x219 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x220 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x221 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x222 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x223 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x224 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x225 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x226 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x227 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x228 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x229 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x230 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x231 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x232 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x233 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x234 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x235 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x236 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x237 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x238 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x239 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x240 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x241 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x242 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x243 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x244 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x245 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x246 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x247 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x248 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x249 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x250 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x251 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x252 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x253 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x254 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x255 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x256 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x257 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x258 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x259 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x260 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x261 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x262 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x263 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x264 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x265 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x266 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x267 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x268 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x269 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x270 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x271 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x272 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x273 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x274 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x275 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x276 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x277 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x278 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x279 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x280 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x281 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x282 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x283 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x284 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x285 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x286 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x287 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x288 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x289 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x290 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x291 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x292 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x293 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x294 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x295 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x296 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x297 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x298 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x299 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x300 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x301 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x302 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x303 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x304 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x305 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x306 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x307 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x308 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x309 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x310 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x311 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x312 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x313 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x314 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x315 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x316 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x317 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x318 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x319 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x320 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x321 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x322 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x323 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x324 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x325 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x326 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x327 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x328 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x329 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x330 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x331 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x332 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x333 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x334 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x335 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x336 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x337 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x338 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x339 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x340 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x341 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x342 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x343 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x344 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x345 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x346 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x347 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x348 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x349 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x350 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x351 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x352 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x353 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x354 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x355 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x356 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x357 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x358 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x359 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x360 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x361 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x362 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x363 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x364 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x365 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x366 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x367 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x368 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x369 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x370 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x371 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x372 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x373 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x374 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x375 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x376 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x377 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x378 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x379 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x380 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x381 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x382 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x383 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x384 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x385 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x386 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x387 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x388 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x389 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x390 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x391 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x392 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x393 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x394 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x395 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x396 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x397 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x398 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x399 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x400 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x401 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x402 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x403 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x404 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x405 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x406 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x407 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x408 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x409 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x410 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x411 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x412 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x413 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x414 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x415 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x416 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x417 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x418 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x419 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x420 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x421 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x422 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x423 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x424 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x425 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x426 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x427 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x428 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x429 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x430 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x431 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x432 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x433 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x434 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x435 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x436 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x437 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x438 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x439 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x440 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x441 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x442 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x443 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x444 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x445 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x446 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x447 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x448 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x449 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x450 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x451 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x452 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x453 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x454 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x455 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x456 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x457 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x458 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x459 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x460 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x461 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x462 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x463 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x464 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x465 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x466 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x467 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x468 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x469 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x470 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x471 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x472 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x473 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x474 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x475 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x476 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x477 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x478 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x479 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x480 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x481 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x482 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x483 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x484 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x485 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x486 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x487 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x488 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x489 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x490 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x491 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x492 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x493 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x494 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x495 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x496 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x497 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x498 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x499 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x500 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x501 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x502 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x503 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x504 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x505 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x506 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x507 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x508 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x509 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x510 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x511 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x512 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x513 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x514 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x515 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x516 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x517 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x518 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x519 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x520 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x521 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x522 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x523 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x524 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x525 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x526 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x527 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x528 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x529 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x530 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x531 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x532 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x533 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x534 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x535 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x536 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x537 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x538 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x539 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x540 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x541 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x542 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x543 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x544 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x545 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x546 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x547 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x548 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x549 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x550 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x551 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x552 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x553 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x554 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x555 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x556 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x557 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x558 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x559 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x560 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x561 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x562 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x563 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x564 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x565 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x566 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x567 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x568 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x569 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x570 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x571 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x572 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x573 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x574 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x575 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x576 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x577 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x578 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x579 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x580 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x581 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x582 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x583 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x584 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x585 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x586 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x587 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x588 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x589 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x590 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x591 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x592 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x593 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x594 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x595 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x596 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x597 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x598 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x599 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x600 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x601 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x602 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x603 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x604 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x605 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x606 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x607 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x608 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x609 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x610 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x611 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x612 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x613 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x614 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x615 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x616 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x617 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x618 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x619 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x620 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x621 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x622 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x623 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x624 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x625 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x626 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x627 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x628 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x629 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x630 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x631 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x632 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x633 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x634 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x635 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x636 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x637 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x638 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x639 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x640 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x641 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x642 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x643 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x644 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x645 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x646 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x647 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x648 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x649 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x650 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x651 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x652 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x653 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x654 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x655 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x656 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x657 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x658 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x659 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x660 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x661 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x662 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x663 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x664 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x665 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x666 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x667 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x668 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x669 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x670 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x671 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x672 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x673 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x674 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x675 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x676 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x677 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x678 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x679 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x680 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x681 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x682 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x683 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x684 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x685 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x686 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x687 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x688 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x689 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x690 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x691 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x692 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x693 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x694 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x695 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x696 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x697 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x698 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x699 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x700 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x701 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x702 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x703 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x704 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x705 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x706 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x707 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x708 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x709 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x710 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x711 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x712 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x713 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x714 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x715 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x716 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x717 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x718 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x719 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x720 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x721 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x722 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x723 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x724 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x725 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x726 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x727 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x728 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x729 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x730 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x731 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x732 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x733 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x734 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x735 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x736 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x737 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x738 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x739 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x740 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x741 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x742 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x743 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x744 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x745 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x746 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x747 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x748 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x749 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x750 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x751 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x752 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x753 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x754 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x755 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x756 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x757 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x758 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x759 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x760 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x761 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x762 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x763 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x764 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x765 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x766 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x767 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x768 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x769 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x770 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x771 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x772 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x773 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x774 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x775 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x776 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x777 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x778 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x779 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x780 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x781 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x782 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x783 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x784 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x785 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x786 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x787 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x788 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x789 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x790 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x791 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x792 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x793 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x794 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x795 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x796 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x797 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x798 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x799 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x800 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x801 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x802 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x803 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x804 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x805 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x806 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x807 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x808 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x809 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x810 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x811 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x812 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x813 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x814 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x815 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x816 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x817 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x818 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x819 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x820 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x821 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x822 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x823 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x824 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x825 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x826 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x827 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x828 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x829 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x830 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x831 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x832 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x833 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x834 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x835 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x836 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x837 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x838 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x839 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x840 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x841 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x842 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x843 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x844 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x845 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x846 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x847 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x848 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x849 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x850 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x851 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x852 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x853 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x854 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x855 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x856 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x857 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x858 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x859 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x860 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x861 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x862 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x863 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x864 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x865 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x866 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x867 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x868 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x869 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x870 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x871 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x872 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x873 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x874 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x875 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x876 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x877 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x878 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x879 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x880 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x881 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x882 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x883 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x884 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x885 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x886 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x887 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x888 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x889 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x890 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x891 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x892 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x893 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x894 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x895 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x896 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x897 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x898 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x899 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x900 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x901 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x902 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x903 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x904 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x905 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x906 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x907 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x908 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x909 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x910 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x911 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x912 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x913 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x914 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x915 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x916 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x917 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x918 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x919 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x920 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x921 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x922 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x923 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x924 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x925 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x926 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x927 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x928 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x929 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x930 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x931 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x932 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x933 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x934 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x935 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x936 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x937 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x938 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x939 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x940 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x941 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x942 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x943 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x944 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x945 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x946 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x947 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x948 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x949 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x950 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x951 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x952 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x953 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x954 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x955 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x956 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x957 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x958 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x959 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x960 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x961 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x962 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x963 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x964 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x965 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x966 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x967 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x968 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x969 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x970 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x971 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x972 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x973 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x974 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x975 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x976 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x977 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x978 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x979 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x980 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x981 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x982 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x983 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x984 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x985 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x986 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x987 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x988 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x989 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x990 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x991 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x992 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x993 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x994 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x995 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x996 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x997 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x998 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x999 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1000 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1001 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1002 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1003 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1004 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1005 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1006 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1007 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1008 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1009 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1010 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1011 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1012 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1013 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1014 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1015 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1016 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1017 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1018 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1019 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1020 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1021 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1022 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1023 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1024 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1025 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1026 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1027 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1028 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1029 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1030 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1031 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1032 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1033 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1034 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1035 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1036 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1037 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1038 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1039 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1040 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1041 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1042 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1043 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1044 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1045 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1046 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1047 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1048 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1049 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1050 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1051 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1052 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1053 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1054 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1055 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1056 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1057 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1058 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1059 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1060 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1061 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1062 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1063 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1064 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1065 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1066 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1067 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1068 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1069 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1070 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1071 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1072 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1073 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1074 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1075 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1076 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1077 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1078 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1079 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1080 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1081 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1082 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1083 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1084 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1085 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1086 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1087 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1088 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1089 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1090 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1091 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1092 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1093 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1094 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1095 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1096 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1097 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1098 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1099 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1100 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1101 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1102 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1103 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1104 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1105 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1106 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1107 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1108 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1109 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1110 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1111 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1112 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1113 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1114 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1115 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1116 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1117 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1118 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1119 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1120 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1121 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1122 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1123 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1124 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1125 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1126 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1127 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1128 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1129 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1130 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1131 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1132 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1133 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1134 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1135 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1136 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1137 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1138 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1139 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1140 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1141 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1142 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1143 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1144 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1145 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1146 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1147 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1148 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1149 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1150 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1151 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1152 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1153 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1154 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1155 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1156 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1157 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1158 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1159 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1160 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1161 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1162 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1163 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1164 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1165 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1166 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1167 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1168 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1169 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1170 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1171 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1172 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1173 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1174 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1175 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1176 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1177 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1178 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1179 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1180 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1181 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1182 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1183 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1184 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1185 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1186 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1187 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1188 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1189 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1190 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1191 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1192 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1193 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1194 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1195 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1196 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1197 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1198 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1199 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1200 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1201 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1202 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1203 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1204 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1205 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1206 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1207 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1208 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1209 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1210 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1211 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1212 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1213 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1214 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1215 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1216 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1217 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1218 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1219 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1220 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1221 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1222 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1223 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1224 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1225 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1226 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1227 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1228 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1229 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1230 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1231 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1232 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1233 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1234 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1235 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1236 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1237 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1238 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1239 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1240 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1241 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1242 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1243 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1244 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1245 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1246 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1247 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1248 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1249 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1250 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1251 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1252 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1253 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1254 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1255 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1256 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1257 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1258 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1259 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1260 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1261 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1262 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1263 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1264 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1265 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1266 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1267 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1268 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1269 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1270 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1271 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1272 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1273 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1274 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1275 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1276 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1277 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1278 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1279 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1280 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1281 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1282 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1283 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1284 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1285 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1286 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1287 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1288 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1289 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1290 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1291 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1292 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1293 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1294 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1295 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1296 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1297 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1298 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1299 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1300 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1301 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1302 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1303 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1304 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1305 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1306 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1307 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1308 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1309 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1310 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1311 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1312 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1313 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1314 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1315 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1316 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1317 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1318 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1319 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1320 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1321 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1322 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1323 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1324 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1325 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1326 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1327 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1328 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1329 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1330 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1331 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1332 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1333 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1334 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1335 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1336 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1337 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1338 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1339 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1340 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1341 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1342 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1343 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1344 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1345 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1346 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1347 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1348 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1349 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1350 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1351 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1352 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1353 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1354 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1355 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1356 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1357 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1358 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1359 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1360 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1361 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1362 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1363 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1364 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1365 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1366 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1367 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1368 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1369 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1370 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1371 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1372 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1373 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1374 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1375 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1376 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1377 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1378 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1379 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1380 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1381 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1382 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1383 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1384 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1385 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1386 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1387 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1388 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1389 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1390 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1391 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1392 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1393 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1394 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1395 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1396 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1397 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1398 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1399 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1400 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1401 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1402 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1403 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1404 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1405 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1406 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1407 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1408 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1409 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1410 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1411 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1412 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1413 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1414 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1415 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1416 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1417 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1418 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1419 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1420 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1421 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1422 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1423 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1424 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1425 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1426 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1427 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1428 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1429 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1430 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1431 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1432 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1433 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1434 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1435 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1436 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1437 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1438 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1439 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1440 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1441 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1442 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1443 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1444 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1445 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1446 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1447 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1448 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1449 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1450 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1451 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1452 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1453 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1454 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1455 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1456 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1457 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1458 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1459 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1460 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1461 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1462 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1463 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1464 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1465 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1466 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1467 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1468 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1469 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1470 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1471 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1472 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1473 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1474 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1475 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1476 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1477 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1478 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1479 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1480 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1481 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1482 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1483 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1484 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1485 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1486 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1487 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1488 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1489 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1490 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1491 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1492 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1493 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1494 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1495 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1496 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1497 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1498 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1499 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1500 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1501 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1502 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1503 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1504 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1505 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1506 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1507 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1508 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1509 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1510 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1511 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1512 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1513 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1514 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1515 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1516 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1517 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1518 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1519 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1520 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1521 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1522 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1523 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1524 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1525 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1526 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1527 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1528 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1529 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1530 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1531 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1532 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1533 = Var(within=Reals,bounds=(None,None),initialize=0)
m.x1534 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1535 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1536 = Var(within=Reals,bounds=(0,None),initialize=0)
m.x1537 = Var(within=Reals,bounds=(0,None),initialize=0)
m.b1538 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1539 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1540 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1541 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1542 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1543 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1544 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1545 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1546 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1547 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1548 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1549 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1550 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1551 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1552 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1553 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1554 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1555 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1556 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1557 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1558 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1559 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1560 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1561 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1562 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1563 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1564 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1565 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1566 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1567 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1568 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1569 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1570 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1571 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1572 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1573 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1574 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1575 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1576 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1577 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1578 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1579 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1580 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1581 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1582 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1583 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1584 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1585 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1586 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1587 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1588 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1589 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1590 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1591 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1592 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1593 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1594 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1595 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1596 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1597 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1598 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1599 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1600 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1601 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1602 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1603 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1604 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1605 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1606 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1607 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1608 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1609 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1610 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1611 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1612 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1613 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1614 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1615 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1616 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1617 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1618 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1619 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1620 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1621 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1622 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1623 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1624 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1625 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1626 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1627 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1628 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1629 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1630 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1631 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1632 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1633 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1634 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1635 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1636 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1637 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1638 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1639 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1640 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1641 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1642 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1643 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1644 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1645 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1646 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1647 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1648 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1649 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1650 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1651 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1652 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1653 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1654 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1655 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1656 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1657 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1658 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1659 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1660 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1661 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1662 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1663 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1664 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1665 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1666 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1667 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1668 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1669 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1670 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1671 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1672 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1673 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1674 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1675 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1676 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1677 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1678 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1679 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1680 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1681 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1682 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1683 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1684 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1685 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1686 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1687 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1688 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1689 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1690 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1691 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1692 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1693 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1694 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1695 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1696 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1697 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1698 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1699 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1700 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1701 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1702 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1703 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1704 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1705 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1706 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1707 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1708 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1709 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1710 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1711 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1712 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1713 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1714 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1715 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1716 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1717 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1718 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1719 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1720 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1721 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1722 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1723 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1724 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1725 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1726 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1727 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1728 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1729 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1730 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1731 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1732 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1733 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1734 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1735 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1736 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1737 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1738 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1739 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1740 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1741 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1742 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1743 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1744 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1745 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1746 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1747 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1748 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1749 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1750 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1751 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1752 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1753 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1754 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1755 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1756 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1757 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1758 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1759 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1760 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1761 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1762 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1763 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1764 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1765 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1766 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1767 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1768 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1769 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1770 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1771 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1772 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1773 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1774 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1775 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1776 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1777 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1778 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1779 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1780 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1781 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1782 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1783 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1784 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1785 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1786 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1787 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1788 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1789 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1790 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1791 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1792 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1793 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1794 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1795 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1796 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1797 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1798 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1799 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1800 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1801 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1802 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1803 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1804 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1805 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1806 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1807 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1808 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1809 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1810 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1811 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1812 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1813 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1814 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1815 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1816 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1817 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1818 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1819 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1820 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1821 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1822 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1823 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1824 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1825 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1826 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1827 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1828 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1829 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1830 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1831 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1832 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1833 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1834 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1835 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1836 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1837 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1838 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1839 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1840 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1841 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1842 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1843 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1844 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1845 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1846 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1847 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1848 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1849 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1850 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1851 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1852 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1853 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1854 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1855 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1856 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1857 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1858 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1859 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1860 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1861 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1862 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1863 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1864 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1865 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1866 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1867 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1868 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1869 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1870 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1871 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1872 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1873 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1874 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1875 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1876 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1877 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1878 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1879 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1880 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1881 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1882 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1883 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1884 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1885 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1886 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1887 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1888 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1889 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1890 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1891 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1892 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1893 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1894 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1895 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1896 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1897 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1898 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1899 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1900 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1901 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1902 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1903 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1904 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1905 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1906 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1907 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1908 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1909 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1910 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1911 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1912 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1913 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1914 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1915 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1916 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1917 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1918 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1919 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1920 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1921 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1922 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1923 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1924 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1925 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1926 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1927 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1928 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1929 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1930 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1931 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1932 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1933 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1934 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1935 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1936 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1937 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1938 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1939 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1940 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1941 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1942 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1943 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1944 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1945 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1946 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1947 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1948 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1949 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1950 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1951 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1952 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1953 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1954 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1955 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1956 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1957 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1958 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1959 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1960 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1961 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1962 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1963 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1964 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1965 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1966 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1967 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1968 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1969 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1970 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1971 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1972 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1973 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1974 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1975 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1976 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1977 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1978 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1979 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1980 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1981 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1982 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1983 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1984 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1985 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1986 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1987 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1988 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1989 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1990 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1991 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1992 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1993 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1994 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1995 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1996 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1997 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1998 = Var(within=Binary,bounds=(0,1),initialize=0)
m.b1999 = Var(within=Binary,bounds=(0,1),initialize=0)
m.obj = Objective(expr=-(-(0.00196850393700787*m.x8)**2 - (0.00196850393700787*m.x9)**2 - (0.00196850393700787*m.x10)**2
- (0.00196850393700787*m.x11)**2 - (0.00196850393700787*m.x12)**2 - (0.00196850393700787*m.x13)
**2) - 0.00393700787401575*m.x2 - 0.00393700787401575*m.x3 - 0.00393700787401575*m.x4
- 0.00393700787401575*m.x5 - 0.00393700787401575*m.x6 - 0.00393700787401575*m.x7
, sense=minimize)
m.c2 = Constraint(expr= m.x2 - m.x14 - m.x20 - m.x26 - m.x32 - m.x38 - m.x44 - m.x50 - m.x56 - m.x62 - m.x68 - m.x74
- m.x80 - m.x86 - m.x92 - m.x98 - m.x104 - m.x110 - m.x116 - m.x122 - m.x128 - m.x134 - m.x140
- m.x146 - m.x152 - m.x158 - m.x164 - m.x170 - m.x176 - m.x182 - m.x188 - m.x194 - m.x200
- m.x206 - m.x212 - m.x218 - m.x224 - m.x230 - m.x236 - m.x242 - m.x248 - m.x254 - m.x260
- m.x266 - m.x272 - m.x278 - m.x284 - m.x290 - m.x296 - m.x302 - m.x308 - m.x314 - m.x320
- m.x326 - m.x332 - m.x338 - m.x344 - m.x350 - m.x356 - m.x362 - m.x368 - m.x374 - m.x380
- m.x386 - m.x392 - m.x398 - m.x404 - m.x410 - m.x416 - m.x422 - m.x428 - m.x434 - m.x440
- m.x446 - m.x452 - m.x458 - m.x464 - m.x470 - m.x476 - m.x482 - m.x488 - m.x494 - m.x500
- m.x506 - m.x512 - m.x518 - m.x524 - m.x530 - m.x536 - m.x542 - m.x548 - m.x554 - m.x560
- m.x566 - m.x572 - m.x578 - m.x584 - m.x590 - m.x596 - m.x602 - m.x608 - m.x614 - m.x620
- m.x626 - m.x632 - m.x638 - m.x644 - m.x650 - m.x656 - m.x662 - m.x668 - m.x674 - m.x680
- m.x686 - m.x692 - m.x698 - m.x704 - m.x710 - m.x716 - m.x722 - m.x728 - m.x734 - m.x740
- m.x746 - m.x752 - m.x758 - m.x764 - m.x770 - m.x776 - m.x782 - m.x788 - m.x794 - m.x800
- m.x806 - m.x812 - m.x818 - m.x824 - m.x830 - m.x836 - m.x842 - m.x848 - m.x854 - m.x860
- m.x866 - m.x872 - m.x878 - m.x884 - m.x890 - m.x896 - m.x902 - m.x908 - m.x914 - m.x920
- m.x926 - m.x932 - m.x938 - m.x944 - m.x950 - m.x956 - m.x962 - m.x968 - m.x974 - m.x980
- m.x986 - m.x992 - m.x998 - m.x1004 - m.x1010 - m.x1016 - m.x1022 - m.x1028 - m.x1034 - m.x1040
- m.x1046 - m.x1052 - m.x1058 - m.x1064 - m.x1070 - m.x1076 - m.x1082 - m.x1088 - m.x1094
- m.x1100 - m.x1106 - m.x1112 - m.x1118 - m.x1124 - m.x1130 - m.x1136 - m.x1142 - m.x1148
- m.x1154 - m.x1160 - m.x1166 - m.x1172 - m.x1178 - m.x1184 - m.x1190 - m.x1196 - m.x1202
- m.x1208 - m.x1214 - m.x1220 - m.x1226 - m.x1232 - m.x1238 - m.x1244 - m.x1250 - m.x1256
- m.x1262 - m.x1268 - m.x1274 - m.x1280 - m.x1286 - m.x1292 - m.x1298 - m.x1304 - m.x1310
- m.x1316 - m.x1322 - m.x1328 - m.x1334 - m.x1340 - m.x1346 - m.x1352 - m.x1358 - m.x1364
- m.x1370 - m.x1376 - m.x1382 - m.x1388 - m.x1394 - m.x1400 - m.x1406 - m.x1412 - m.x1418
- m.x1424 - m.x1430 - m.x1436 - m.x1442 - m.x1448 - m.x1454 - m.x1460 - m.x1466 - m.x1472
- m.x1478 - m.x1484 - m.x1490 - m.x1496 - m.x1502 - m.x1508 - m.x1514 - m.x1520 - m.x1526
- m.x1532 == 0)
m.c3 = Constraint(expr= m.x3 - m.x15 - m.x21 - m.x27 - m.x33 - m.x39 - m.x45 - m.x51 - m.x57 - m.x63 - m.x69 - m.x75
- m.x81 - m.x87 - m.x93 - m.x99 - m.x105 - m.x111 - m.x117 - m.x123 - m.x129 - m.x135 - m.x141
- m.x147 - m.x153 - m.x159 - m.x165 - m.x171 - m.x177 - m.x183 - m.x189 - m.x195 - m.x201
- m.x207 - m.x213 - m.x219 - m.x225 - m.x231 - m.x237 - m.x243 - m.x249 - m.x255 - m.x261
- m.x267 - m.x273 - m.x279 - m.x285 - m.x291 - m.x297 - m.x303 - m.x309 - m.x315 - m.x321
- m.x327 - m.x333 - m.x339 - m.x345 - m.x351 - m.x357 - m.x363 - m.x369 - m.x375 - m.x381
- m.x387 - m.x393 - m.x399 - m.x405 - m.x411 - m.x417 - m.x423 - m.x429 - m.x435 - m.x441
- m.x447 - m.x453 - m.x459 - m.x465 - m.x471 - m.x477 - m.x483 - m.x489 - m.x495 - m.x501
- m.x507 - m.x513 - m.x519 - m.x525 - m.x531 - m.x537 - m.x543 - m.x549 - m.x555 - m.x561
- m.x567 - m.x573 - m.x579 - m.x585 - m.x591 - m.x597 - m.x603 - m.x609 - m.x615 - m.x621
- m.x627 - m.x633 - m.x639 - m.x645 - m.x651 - m.x657 - m.x663 - m.x669 - m.x675 - m.x681
- m.x687 - m.x693 - m.x699 - m.x705 - m.x711 - m.x717 - m.x723 - m.x729 - m.x735 - m.x741
- m.x747 - m.x753 - m.x759 - m.x765 - m.x771 - m.x777 - m.x783 - m.x789 - m.x795 - m.x801
- m.x807 - m.x813 - m.x819 - m.x825 - m.x831 - m.x837 - m.x843 - m.x849 - m.x855 - m.x861
- m.x867 - m.x873 - m.x879 - m.x885 - m.x891 - m.x897 - m.x903 - m.x909 - m.x915 - m.x921
- m.x927 - m.x933 - m.x939 - m.x945 - m.x951 - m.x957 - m.x963 - m.x969 - m.x975 - m.x981
- m.x987 - m.x993 - m.x999 - m.x1005 - m.x1011 - m.x1017 - m.x1023 - m.x1029 - m.x1035 - m.x1041
- m.x1047 - m.x1053 - m.x1059 - m.x1065 - m.x1071 - m.x1077 - m.x1083 - m.x1089 - m.x1095
- m.x1101 - m.x1107 - m.x1113 - m.x1119 - m.x1125 - m.x1131 - m.x1137 - m.x1143 - m.x1149
- m.x1155 - m.x1161 - m.x1167 - m.x1173 - m.x1179 - m.x1185 - m.x1191 - m.x1197 - m.x1203
- m.x1209 - m.x1215 - m.x1221 - m.x1227 - m.x1233 - m.x1239 - m.x1245 - m.x1251 - m.x1257
- m.x1263 - m.x1269 - m.x1275 - m.x1281 - m.x1287 - m.x1293 - m.x1299 - m.x1305 - m.x1311
- m.x1317 - m.x1323 - m.x1329 - m.x1335 - m.x1341 - m.x1347 - m.x1353 - m.x1359 - m.x1365
- m.x1371 - m.x1377 - m.x1383 - m.x1389 - m.x1395 - m.x1401 - m.x1407 - m.x1413 - m.x1419
- m.x1425 - m.x1431 - m.x1437 - m.x1443 - m.x1449 - m.x1455 - m.x1461 - m.x1467 - m.x1473
- m.x1479 - m.x1485 - m.x1491 - m.x1497 - m.x1503 - m.x1509 - m.x1515 - m.x1521 - m.x1527
- m.x1533 == 0)
m.c4 = Constraint(expr= m.x4 - m.x16 - m.x22 - m.x28 - m.x34 - m.x40 - m.x46 - m.x52 - m.x58 - m.x64 - m.x70 - m.x76
- m.x82 - m.x88 - m.x94 - m.x100 - m.x106 - m.x112 - m.x118 - m.x124 - m.x130 - m.x136 - m.x142
- m.x148 - m.x154 - m.x160 - m.x166 - m.x172 - m.x178 - m.x184 - m.x190 - m.x196 - m.x202
- m.x208 - m.x214 - m.x220 - m.x226 - m.x232 - m.x238 - m.x244 - m.x250 - m.x256 - m.x262
- m.x268 - m.x274 - m.x280 - m.x286 - m.x292 - m.x298 - m.x304 - m.x310 - m.x316 - m.x322
- m.x328 - m.x334 - m.x340 - m.x346 - m.x352 - m.x358 - m.x364 - m.x370 - m.x376 - m.x382
- m.x388 - m.x394 - m.x400 - m.x406 - m.x412 - m.x418 - m.x424 - m.x430 - m.x436 - m.x442
- m.x448 - m.x454 - m.x460 - m.x466 - m.x472 - m.x478 - m.x484 - m.x490 - m.x496 - m.x502
- m.x508 - m.x514 - m.x520 - m.x526 - m.x532 - m.x538 - m.x544 - m.x550 - m.x556 - m.x562
- m.x568 - m.x574 - m.x580 - m.x586 - m.x592 - m.x598 - m.x604 - m.x610 - m.x616 - m.x622
- m.x628 - m.x634 - m.x640 - m.x646 - m.x652 - m.x658 - m.x664 - m.x670 - m.x676 - m.x682
- m.x688 - m.x694 - m.x700 - m.x706 - m.x712 - m.x718 - m.x724 - m.x730 - m.x736 - m.x742
- m.x748 - m.x754 - m.x760 - m.x766 - m.x772 - m.x778 - m.x784 - m.x790 - m.x796 - m.x802
- m.x808 - m.x814 - m.x820 - m.x826 - m.x832 - m.x838 - m.x844 - m.x850 - m.x856 - m.x862
- m.x868 - m.x874 - m.x880 - m.x886 - m.x892 - m.x898 - m.x904 - m.x910 - m.x916 - m.x922
- m.x928 - m.x934 - m.x940 - m.x946 - m.x952 - m.x958 - m.x964 - m.x970 - m.x976 - m.x982
- m.x988 - m.x994 - m.x1000 - m.x1006 - m.x1012 - m.x1018 - m.x1024 - m.x1030 - m.x1036
- m.x1042 - m.x1048 - m.x1054 - m.x1060 - m.x1066 - m.x1072 - m.x1078 - m.x1084 - m.x1090
- m.x1096 - m.x1102 - m.x1108 - m.x1114 - m.x1120 - m.x1126 - m.x1132 - m.x1138 - m.x1144
- m.x1150 - m.x1156 - m.x1162 - m.x1168 - m.x1174 - m.x1180 - m.x1186 - m.x1192 - m.x1198
- m.x1204 - m.x1210 - m.x1216 - m.x1222 - m.x1228 - m.x1234 - m.x1240 - m.x1246 - m.x1252
- m.x1258 - m.x1264 - m.x1270 - m.x1276 - m.x1282 - m.x1288 - m.x1294 - m.x1300 - m.x1306
- m.x1312 - m.x1318 - m.x1324 - m.x1330 - m.x1336 - m.x1342 - m.x1348 - m.x1354 - m.x1360
- m.x1366 - m.x1372 - m.x1378 - m.x1384 - m.x1390 - m.x1396 - m.x1402 - m.x1408 - m.x1414
- m.x1420 - m.x1426 - m.x1432 - m.x1438 - m.x1444 - m.x1450 - m.x1456 - m.x1462 - m.x1468
- m.x1474 - m.x1480 - m.x1486 - m.x1492 - m.x1498 - m.x1504 - m.x1510 - m.x1516 - m.x1522
- m.x1528 - m.x1534 == 0)
m.c5 = Constraint(expr= m.x5 - m.x17 - m.x23 - m.x29 - m.x35 - m.x41 - m.x47 - m.x53 - m.x59 - m.x65 - m.x71 - m.x77
- m.x83 - m.x89 - m.x95 - m.x101 - m.x107 - m.x113 - m.x119 - m.x125 - m.x131 - m.x137 - m.x143
- m.x149 - m.x155 - m.x161 - m.x167 - m.x173 - m.x179 - m.x185 - m.x191 - m.x197 - m.x203
- m.x209 - m.x215 - m.x221 - m.x227 - m.x233 - m.x239 - m.x245 - m.x251 - m.x257 - m.x263
- m.x269 - m.x275 - m.x281 - m.x287 - m.x293 - m.x299 - m.x305 - m.x311 - m.x317 - m.x323
- m.x329 - m.x335 - m.x341 - m.x347 - m.x353 - m.x359 - m.x365 - m.x371 - m.x377 - m.x383
- m.x389 - m.x395 - m.x401 - m.x407 - m.x413 - m.x419 - m.x425 - m.x431 - m.x437 - m.x443
- m.x449 - m.x455 - m.x461 - m.x467 - m.x473 - m.x479 - m.x485 - m.x491 - m.x497 - m.x503
- m.x509 - m.x515 - m.x521 - m.x527 - m.x533 - m.x539 - m.x545 - m.x551 - m.x557 - m.x563
- m.x569 - m.x575 - m.x581 - m.x587 - m.x593 - m.x599 - m.x605 - m.x611 - m.x617 - m.x623
- m.x629 - m.x635 - m.x641 - m.x647 - m.x653 - m.x659 - m.x665 - m.x671 - m.x677 - m.x683
- m.x689 - m.x695 - m.x701 - m.x707 - m.x713 - m.x719 - m.x725 - m.x731 - m.x737 - m.x743
- m.x749 - m.x755 - m.x761 - m.x767 - m.x773 - m.x779 - m.x785 - m.x791 - m.x797 - m.x803
- m.x809 - m.x815 - m.x821 - m.x827 - m.x833 - m.x839 - m.x845 - m.x851 - m.x857 - m.x863
- m.x869 - m.x875 - m.x881 - m.x887 - m.x893 - m.x899 - m.x905 - m.x911 - m.x917 - m.x923
- m.x929 - m.x935 - m.x941 - m.x947 - m.x953 - m.x959 - m.x965 - m.x971 - m.x977 - m.x983
- m.x989 - m.x995 - m.x1001 - m.x1007 - m.x1013 - m.x1019 - m.x1025 - m.x1031 - m.x1037
- m.x1043 - m.x1049 - m.x1055 - m.x1061 - m.x1067 - m.x1073 - m.x1079 - m.x1085 - m.x1091
- m.x1097 - m.x1103 - m.x1109 - m.x1115 - m.x1121 - m.x1127 - m.x1133 - m.x1139 - m.x1145
- m.x1151 - m.x1157 - m.x1163 - m.x1169 - m.x1175 - m.x1181 - m.x1187 - m.x1193 - m.x1199
- m.x1205 - m.x1211 - m.x1217 - m.x1223 - m.x1229 - m.x1235 - m.x1241 - m.x1247 - m.x1253
- m.x1259 - m.x1265 - m.x1271 - m.x1277 - m.x1283 - m.x1289 - m.x1295 - m.x1301 - m.x1307
- m.x1313 - m.x1319 - m.x1325 - m.x1331 - m.x1337 - m.x1343 - m.x1349 - m.x1355 - m.x1361
- m.x1367 - m.x1373 - m.x1379 - m.x1385 - m.x1391 - m.x1397 - m.x1403 - m.x1409 - m.x1415
- m.x1421 - m.x1427 - m.x1433 - m.x1439 - m.x1445 - m.x1451 - m.x1457 - m.x1463 - m.x1469
- m.x1475 - m.x1481 - m.x1487 - m.x1493 - m.x1499 - m.x1505 - m.x1511 - m.x1517 - m.x1523
- m.x1529 - m.x1535 == 0)
m.c6 = Constraint(expr= m.x6 - m.x18 - m.x24 - m.x30 - m.x36 - m.x42 - m.x48 - m.x54 - m.x60 - m.x66 - m.x72 - m.x78
- m.x84 - m.x90 - m.x96 - m.x102 - m.x108 - m.x114 - m.x120 - m.x126 - m.x132 - m.x138 - m.x144
- m.x150 - m.x156 - m.x162 - m.x168 - m.x174 - m.x180 - m.x186 - m.x192 - m.x198 - m.x204
- m.x210 - m.x216 - m.x222 - m.x228 - m.x234 - m.x240 - m.x246 - m.x252 - m.x258 - m.x264
- m.x270 - m.x276 - m.x282 - m.x288 - m.x294 - m.x300 - m.x306 - m.x312 - m.x318 - m.x324
- m.x330 - m.x336 - m.x342 - m.x348 - m.x354 - m.x360 - m.x366 - m.x372 - m.x378 - m.x384
- m.x390 - m.x396 - m.x402 - m.x408 - m.x414 - m.x420 - m.x426 - m.x432 - m.x438 - m.x444
- m.x450 - m.x456 - m.x462 - m.x468 - m.x474 - m.x480 - m.x486 - m.x492 - m.x498 - m.x504
- m.x510 - m.x516 - m.x522 - m.x528 - m.x534 - m.x540 - m.x546 - m.x552 - m.x558 - m.x564
- m.x570 - m.x576 - m.x582 - m.x588 - m.x594 - m.x600 - m.x606 - m.x612 - m.x618 - m.x624
- m.x630 - m.x636 - m.x642 - m.x648 - m.x654 - m.x660 - m.x666 - m.x672 - m.x678 - m.x684
- m.x690 - m.x696 - m.x702 - m.x708 - m.x714 - m.x720 - m.x726 - m.x732 - m.x738 - m.x744
- m.x750 - m.x756 - m.x762 - m.x768 - m.x774 - m.x780 - m.x786 - m.x792 - m.x798 - m.x804
- m.x810 - m.x816 - m.x822 - m.x828 - m.x834 - m.x840 - m.x846 - m.x852 - m.x858 - m.x864
- m.x870 - m.x876 - m.x882 - m.x888 - m.x894 - m.x900 - m.x906 - m.x912 - m.x918 - m.x924
- m.x930 - m.x936 - m.x942 - m.x948 - m.x954 - m.x960 - m.x966 - m.x972 - m.x978 - m.x984
- m.x990 - m.x996 - m.x1002 - m.x1008 - m.x1014 - m.x1020 - m.x1026 - m.x1032 - m.x1038
- m.x1044 - m.x1050 - m.x1056 - m.x1062 - m.x1068 - m.x1074 - m.x1080 - m.x1086 - m.x1092
- m.x1098 - m.x1104 - m.x1110 - m.x1116 - m.x1122 - m.x1128 - m.x1134 - m.x1140 - m.x1146
- m.x1152 - m.x1158 - m.x1164 - m.x1170 - m.x1176 - m.x1182 - m.x1188 - m.x1194 - m.x1200
- m.x1206 - m.x1212 - m.x1218 - m.x1224 - m.x1230 - m.x1236 - m.x1242 - m.x1248 - m.x1254
- m.x1260 - m.x1266 - m.x1272 - m.x1278 - m.x1284 - m.x1290 - m.x1296 - m.x1302 - m.x1308
- m.x1314 - m.x1320 - m.x1326 - m.x1332 - m.x1338 - m.x1344 - m.x1350 - m.x1356 - m.x1362
- m.x1368 - m.x1374 - m.x1380 - m.x1386 - m.x1392 - m.x1398 - m.x1404 - m.x1410 - m.x1416
- m.x1422 - m.x1428 - m.x1434 - m.x1440 - m.x1446 - m.x1452 - m.x1458 - m.x1464 - m.x1470
- m.x1476 - m.x1482 - m.x1488 - m.x1494 - m.x1500 - m.x1506 - m.x1512 - m.x1518 - m.x1524
- m.x1530 - m.x1536 == 0)
m.c7 = Constraint(expr= m.x7 - m.x19 - m.x25 - m.x31 - m.x37 - m.x43 - m.x49 - m.x55 - m.x61 - m.x67 - m.x73 - m.x79
- m.x85 - m.x91 - m.x97 - m.x103 - m.x109 - m.x115 - m.x121 - m.x127 - m.x133 - m.x139 - m.x145
- m.x151 - m.x157 - m.x163 - m.x169 - m.x175 - m.x181 - m.x187 - m.x193 - m.x199 - m.x205
- m.x211 - m.x217 - m.x223 - m.x229 - m.x235 - m.x241 - m.x247 - m.x253 - m.x259 - m.x265
- m.x271 - m.x277 - m.x283 - m.x289 - m.x295 - m.x301 - m.x307 - m.x313 - m.x319 - m.x325
- m.x331 - m.x337 - m.x343 - m.x349 - m.x355 - m.x361 - m.x367 - m.x373 - m.x379 - m.x385
- m.x391 - m.x397 - m.x403 - m.x409 - m.x415 - m.x421 - m.x427 - m.x433 - m.x439 - m.x445
- m.x451 - m.x457 - m.x463 - m.x469 - m.x475 - m.x481 - m.x487 - m.x493 - m.x499 - m.x505
- m.x511 - m.x517 - m.x523 - m.x529 - m.x535 - m.x541 - m.x547 - m.x553 - m.x559 - m.x565
- m.x571 - m.x577 - m.x583 - m.x589 - m.x595 - m.x601 - m.x607 - m.x613 - m.x619 - m.x625
- m.x631 - m.x637 - m.x643 - m.x649 - m.x655 - m.x661 - m.x667 - m.x673 - m.x679 - m.x685
- m.x691 - m.x697 - m.x703 - m.x709 - m.x715 - m.x721 - m.x727 - m.x733 - m.x739 - m.x745
- m.x751 - m.x757 - m.x763 - m.x769 - m.x775 - m.x781 - m.x787 - m.x793 - m.x799 - m.x805
- m.x811 - m.x817 - m.x823 - m.x829 - m.x835 - m.x841 - m.x847 - m.x853 - m.x859 - m.x865
- m.x871 - m.x877 - m.x883 - m.x889 - m.x895 - m.x901 - m.x907 - m.x913 - m.x919 - m.x925
- m.x931 - m.x937 - m.x943 - m.x949 - m.x955 - m.x961 - m.x967 - m.x973 - m.x979 - m.x985
- m.x991 - m.x997 - m.x1003 - m.x1009 - m.x1015 - m.x1021 - m.x1027 - m.x1033 - m.x1039
- m.x1045 - m.x1051 - m.x1057 - m.x1063 - m.x1069 - m.x1075 - m.x1081 - m.x1087 - m.x1093
- m.x1099 - m.x1105 - m.x1111 - m.x1117 - m.x1123 - m.x1129 - m.x1135 - m.x1141 - m.x1147
- m.x1153 - m.x1159 - m.x1165 - m.x1171 - m.x1177 - m.x1183 - m.x1189 - m.x1195 - m.x1201
- m.x1207 - m.x1213 - m.x1219 - m.x1225 - m.x1231 - m.x1237 - m.x1243 - m.x1249 - m.x1255
- m.x1261 - m.x1267 - m.x1273 - m.x1279 - m.x1285 - m.x1291 - m.x1297 - m.x1303 - m.x1309
- m.x1315 - m.x1321 - m.x1327 - m.x1333 - m.x1339 - m.x1345 - m.x1351 - m.x1357 - m.x1363
- m.x1369 - m.x1375 - m.x1381 - m.x1387 - m.x1393 - m.x1399 - m.x1405 - m.x1411 - m.x1417
- m.x1423 - m.x1429 - m.x1435 - m.x1441 - m.x1447 - m.x1453 - m.x1459 - m.x1465 - m.x1471
- m.x1477 - m.x1483 - m.x1489 - m.x1495 - m.x1501 - m.x1507 - m.x1513 - m.x1519 - m.x1525
- m.x1531 - m.x1537 == 0)
m.c8 = Constraint(expr= m.x8 - 36*m.b1538 - 22*m.b1544 - 19*m.b1550 - 17*m.b1556 - 16*m.b1562 - 15*m.b1568
- 15*m.b1574 - 13*m.b1580 - 13*m.b1586 - 12*m.b1592 - 12*m.b1598 - 11*m.b1604 - 11*m.b1610
- 11*m.b1616 - 11*m.b1622 - 11*m.b1628 - 11*m.b1634 - 10*m.b1640 - 10*m.b1646 - 10*m.b1652
- 10*m.b1658 - 10*m.b1664 - 9*m.b1670 - 9*m.b1676 - 9*m.b1682 - 8*m.b1688 - 7*m.b1694
- 7*m.b1700 - 7*m.b1706 - 7*m.b1712 - 7*m.b1718 - 7*m.b1724 - 7*m.b1730 - 7*m.b1736 - 7*m.b1742
- 7*m.b1748 - 6*m.b1754 - 6*m.b1760 - 6*m.b1766 - 6*m.b1772 - 6*m.b1778 - 4*m.b1784 - 4*m.b1790
- 4*m.b1796 - 3*m.b1802 - 3*m.b1808 - 3*m.b1814 - 3*m.b1820 - 3*m.b1826 - 3*m.b1832 - 2*m.b1838
- 2*m.b1844 - 2*m.b1850 - 2*m.b1856 - 2*m.b1862 - 2*m.b1868 - 2*m.b1874 - 2*m.b1880 - 2*m.b1886
- 2*m.b1892 - m.b1898 - m.b1904 - m.b1910 - m.b1916 - m.b1922 - m.b1928 - m.b1934 - m.b1940
- m.b1946 - m.b1952 - m.b1958 - m.b1964 - m.b1970 - m.b1976 - m.b1982 - m.b1988 - m.b1994 == 0)
m.c9 = Constraint(expr= m.x9 - 36*m.b1539 - 22*m.b1545 - 19*m.b1551 - 17*m.b1557 - 16*m.b1563 - 15*m.b1569
- 15*m.b1575 - 13*m.b1581 - 13*m.b1587 - 12*m.b1593 - 12*m.b1599 - 11*m.b1605 - 11*m.b1611
- 11*m.b1617 - 11*m.b1623 - 11*m.b1629 - 11*m.b1635 - 10*m.b1641 - 10*m.b1647 - 10*m.b1653
- 10*m.b1659 - 10*m.b1665 - 9*m.b1671 - 9*m.b1677 - 9*m.b1683 - 8*m.b1689 - 7*m.b1695
- 7*m.b1701 - 7*m.b1707 - 7*m.b1713 - 7*m.b1719 - 7*m.b1725 - 7*m.b1731 - 7*m.b1737 - 7*m.b1743
- 7*m.b1749 - 6*m.b1755 - 6*m.b1761 - 6*m.b1767 - 6*m.b1773 - 6*m.b1779 - 4*m.b1785 - 4*m.b1791
- 4*m.b1797 - 3*m.b1803 - 3*m.b1809 - 3*m.b1815 - 3*m.b1821 - 3*m.b1827 - 3*m.b1833 - 2*m.b1839
- 2*m.b1845 - 2*m.b1851 - 2*m.b1857 - 2*m.b1863 - 2*m.b1869 - 2*m.b1875 - 2*m.b1881 - 2*m.b1887
- 2*m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917 - m.b1923 - m.b1929 - m.b1935 - m.b1941
- m.b1947 - m.b1953 - m.b1959 - m.b1965 - m.b1971 - m.b1977 - m.b1983 - m.b1989 - m.b1995 == 0)
m.c10 = Constraint(expr= m.x10 - 36*m.b1540 - 22*m.b1546 - 19*m.b1552 - 17*m.b1558 - 16*m.b1564 - 15*m.b1570
- 15*m.b1576 - 13*m.b1582 - 13*m.b1588 - 12*m.b1594 - 12*m.b1600 - 11*m.b1606 - 11*m.b1612
- 11*m.b1618 - 11*m.b1624 - 11*m.b1630 - 11*m.b1636 - 10*m.b1642 - 10*m.b1648 - 10*m.b1654
- 10*m.b1660 - 10*m.b1666 - 9*m.b1672 - 9*m.b1678 - 9*m.b1684 - 8*m.b1690 - 7*m.b1696
- 7*m.b1702 - 7*m.b1708 - 7*m.b1714 - 7*m.b1720 - 7*m.b1726 - 7*m.b1732 - 7*m.b1738 - 7*m.b1744
- 7*m.b1750 - 6*m.b1756 - 6*m.b1762 - 6*m.b1768 - 6*m.b1774 - 6*m.b1780 - 4*m.b1786 - 4*m.b1792
- 4*m.b1798 - 3*m.b1804 - 3*m.b1810 - 3*m.b1816 - 3*m.b1822 - 3*m.b1828 - 3*m.b1834 - 2*m.b1840
- 2*m.b1846 - 2*m.b1852 - 2*m.b1858 - 2*m.b1864 - 2*m.b1870 - 2*m.b1876 - 2*m.b1882 - 2*m.b1888
- 2*m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924 - m.b1930 - m.b1936 - m.b1942
- m.b1948 - m.b1954 - m.b1960 - m.b1966 - m.b1972 - m.b1978 - m.b1984 - m.b1990 - m.b1996 == 0)
m.c11 = Constraint(expr= m.x11 - 36*m.b1541 - 22*m.b1547 - 19*m.b1553 - 17*m.b1559 - 16*m.b1565 - 15*m.b1571
- 15*m.b1577 - 13*m.b1583 - 13*m.b1589 - 12*m.b1595 - 12*m.b1601 - 11*m.b1607 - 11*m.b1613
- 11*m.b1619 - 11*m.b1625 - 11*m.b1631 - 11*m.b1637 - 10*m.b1643 - 10*m.b1649 - 10*m.b1655
- 10*m.b1661 - 10*m.b1667 - 9*m.b1673 - 9*m.b1679 - 9*m.b1685 - 8*m.b1691 - 7*m.b1697
- 7*m.b1703 - 7*m.b1709 - 7*m.b1715 - 7*m.b1721 - 7*m.b1727 - 7*m.b1733 - 7*m.b1739 - 7*m.b1745
- 7*m.b1751 - 6*m.b1757 - 6*m.b1763 - 6*m.b1769 - 6*m.b1775 - 6*m.b1781 - 4*m.b1787 - 4*m.b1793
- 4*m.b1799 - 3*m.b1805 - 3*m.b1811 - 3*m.b1817 - 3*m.b1823 - 3*m.b1829 - 3*m.b1835 - 2*m.b1841
- 2*m.b1847 - 2*m.b1853 - 2*m.b1859 - 2*m.b1865 - 2*m.b1871 - 2*m.b1877 - 2*m.b1883 - 2*m.b1889
- 2*m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931 - m.b1937 - m.b1943
- m.b1949 - m.b1955 - m.b1961 - m.b1967 - m.b1973 - m.b1979 - m.b1985 - m.b1991 - m.b1997 == 0)
m.c12 = Constraint(expr= m.x12 - 36*m.b1542 - 22*m.b1548 - 19*m.b1554 - 17*m.b1560 - 16*m.b1566 - 15*m.b1572
- 15*m.b1578 - 13*m.b1584 - 13*m.b1590 - 12*m.b1596 - 12*m.b1602 - 11*m.b1608 - 11*m.b1614
- 11*m.b1620 - 11*m.b1626 - 11*m.b1632 - 11*m.b1638 - 10*m.b1644 - 10*m.b1650 - 10*m.b1656
- 10*m.b1662 - 10*m.b1668 - 9*m.b1674 - 9*m.b1680 - 9*m.b1686 - 8*m.b1692 - 7*m.b1698
- 7*m.b1704 - 7*m.b1710 - 7*m.b1716 - 7*m.b1722 - 7*m.b1728 - 7*m.b1734 - 7*m.b1740 - 7*m.b1746
- 7*m.b1752 - 6*m.b1758 - 6*m.b1764 - 6*m.b1770 - 6*m.b1776 - 6*m.b1782 - 4*m.b1788 - 4*m.b1794
- 4*m.b1800 - 3*m.b1806 - 3*m.b1812 - 3*m.b1818 - 3*m.b1824 - 3*m.b1830 - 3*m.b1836 - 2*m.b1842
- 2*m.b1848 - 2*m.b1854 - 2*m.b1860 - 2*m.b1866 - 2*m.b1872 - 2*m.b1878 - 2*m.b1884 - 2*m.b1890
- 2*m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938 - m.b1944
- m.b1950 - m.b1956 - m.b1962 - m.b1968 - m.b1974 - m.b1980 - m.b1986 - m.b1992 - m.b1998 == 0)
m.c13 = Constraint(expr= m.x13 - 36*m.b1543 - 22*m.b1549 - 19*m.b1555 - 17*m.b1561 - 16*m.b1567 - 15*m.b1573
- 15*m.b1579 - 13*m.b1585 - 13*m.b1591 - 12*m.b1597 - 12*m.b1603 - 11*m.b1609 - 11*m.b1615
- 11*m.b1621 - 11*m.b1627 - 11*m.b1633 - 11*m.b1639 - 10*m.b1645 - 10*m.b1651 - 10*m.b1657
- 10*m.b1663 - 10*m.b1669 - 9*m.b1675 - 9*m.b1681 - 9*m.b1687 - 8*m.b1693 - 7*m.b1699
- 7*m.b1705 - 7*m.b1711 - 7*m.b1717 - 7*m.b1723 - 7*m.b1729 - 7*m.b1735 - 7*m.b1741 - 7*m.b1747
- 7*m.b1753 - 6*m.b1759 - 6*m.b1765 - 6*m.b1771 - 6*m.b1777 - 6*m.b1783 - 4*m.b1789 - 4*m.b1795
- 4*m.b1801 - 3*m.b1807 - 3*m.b1813 - 3*m.b1819 - 3*m.b1825 - 3*m.b1831 - 3*m.b1837 - 2*m.b1843
- 2*m.b1849 - 2*m.b1855 - 2*m.b1861 - 2*m.b1867 - 2*m.b1873 - 2*m.b1879 - 2*m.b1885 - 2*m.b1891
- 2*m.b1897 - m.b1903 - m.b1909 - m.b1915 - m.b1921 - m.b1927 - m.b1933 - m.b1939 - m.b1945
- m.b1951 - m.b1957 - m.b1963 - m.b1969 - m.b1975 - m.b1981 - m.b1987 - m.b1993 - m.b1999 == 0)
m.c14 = Constraint(expr= m.x14 - m.b1538 <= 0)
m.c15 = Constraint(expr= m.x20 - m.b1538 <= 0)
m.c16 = Constraint(expr= m.x26 - m.b1538 <= 0)
m.c17 = Constraint(expr= m.x32 - m.b1538 <= 0)
m.c18 = Constraint(expr= m.x38 - m.b1544 <= 0)
m.c19 = Constraint(expr= m.x44 - m.b1544 <= 0)
m.c20 = Constraint(expr= m.x45 - m.b1545 <= 0)
m.c21 = Constraint(expr= m.x50 - m.b1544 <= 0)
m.c22 = Constraint(expr= m.x51 - m.b1545 <= 0)
m.c23 = Constraint(expr= m.x56 - m.b1544 <= 0)
m.c24 = Constraint(expr= m.x57 - m.b1545 <= 0)
m.c25 = Constraint(expr= m.x62 - m.b1550 <= 0)
m.c26 = Constraint(expr= m.x68 - m.b1550 <= 0)
m.c27 = Constraint(expr= m.x69 - m.b1551 <= 0)
m.c28 = Constraint(expr= m.x74 - m.b1550 <= 0)
m.c29 = Constraint(expr= m.x75 - m.b1551 <= 0)
m.c30 = Constraint(expr= m.x76 - m.b1552 <= 0)
m.c31 = Constraint(expr= m.x80 - m.b1550 <= 0)
m.c32 = Constraint(expr= m.x81 - m.b1551 <= 0)
m.c33 = Constraint(expr= m.x82 - m.b1552 <= 0)
m.c34 = Constraint(expr= m.x86 - m.b1550 <= 0)
m.c35 = Constraint(expr= m.x87 - m.b1551 <= 0)
m.c36 = Constraint(expr= m.x88 - m.b1552 <= 0)
m.c37 = Constraint(expr= m.x92 - m.b1550 <= 0)
m.c38 = Constraint(expr= m.x93 - m.b1551 <= 0)
m.c39 = Constraint(expr= m.x94 - m.b1552 <= 0)
m.c40 = Constraint(expr= m.x98 - m.b1550 <= 0)
m.c41 = Constraint(expr= m.x99 - m.b1551 <= 0)
m.c42 = Constraint(expr= m.x100 - m.b1552 <= 0)
m.c43 = Constraint(expr= m.x104 - m.b1550 <= 0)
m.c44 = Constraint(expr= m.x105 - m.b1551 <= 0)
m.c45 = Constraint(expr= m.x106 - m.b1552 <= 0)
m.c46 = Constraint(expr= m.x110 - m.b1550 <= 0)
m.c47 = Constraint(expr= m.x111 - m.b1551 <= 0)
m.c48 = Constraint(expr= m.x112 - m.b1552 <= 0)
m.c49 = Constraint(expr= m.x116 - m.b1550 <= 0)
m.c50 = Constraint(expr= m.x117 - m.b1551 <= 0)
m.c51 = Constraint(expr= m.x118 - m.b1552 <= 0)
m.c52 = Constraint(expr= m.x122 - m.b1556 <= 0)
m.c53 = Constraint(expr= m.x128 - m.b1556 <= 0)
m.c54 = Constraint(expr= m.x129 - m.b1557 <= 0)
m.c55 = Constraint(expr= m.x130 - m.b1558 <= 0)
m.c56 = Constraint(expr= m.x131 - m.b1559 <= 0)
m.c57 = Constraint(expr= m.x134 - m.b1556 <= 0)
m.c58 = Constraint(expr= m.x135 - m.b1557 <= 0)
m.c59 = Constraint(expr= m.x136 - m.b1558 <= 0)
m.c60 = Constraint(expr= m.x137 - m.b1559 <= 0)
m.c61 = Constraint(expr= m.x140 - m.b1556 <= 0)
m.c62 = Constraint(expr= m.x141 - m.b1557 <= 0)
m.c63 = Constraint(expr= m.x142 - m.b1558 <= 0)
m.c64 = Constraint(expr= m.x143 - m.b1559 <= 0)
m.c65 = Constraint(expr= m.x146 - m.b1556 <= 0)
m.c66 = Constraint(expr= m.x147 - m.b1557 <= 0)
m.c67 = Constraint(expr= m.x148 - m.b1558 <= 0)
m.c68 = Constraint(expr= m.x149 - m.b1559 <= 0)
m.c69 = Constraint(expr= m.x152 - m.b1562 <= 0)
m.c70 = Constraint(expr= m.x158 - m.b1562 <= 0)
m.c71 = Constraint(expr= m.x159 - m.b1563 <= 0)
m.c72 = Constraint(expr= m.x160 - m.b1564 <= 0)
m.c73 = Constraint(expr= m.x161 - m.b1565 <= 0)
m.c74 = Constraint(expr= m.x162 - m.b1566 <= 0)
m.c75 = Constraint(expr= m.x164 - m.b1562 <= 0)
m.c76 = Constraint(expr= m.x165 - m.b1563 <= 0)
m.c77 = Constraint(expr= m.x166 - m.b1564 <= 0)
m.c78 = Constraint(expr= m.x167 - m.b1565 <= 0)
m.c79 = Constraint(expr= m.x168 - m.b1566 <= 0)
m.c80 = Constraint(expr= m.x170 - m.b1568 <= 0)
m.c81 = Constraint(expr= m.x176 - m.b1568 <= 0)
m.c82 = Constraint(expr= m.x177 - m.b1569 <= 0)
m.c83 = Constraint(expr= m.x178 - m.b1570 <= 0)
m.c84 = Constraint(expr= m.x179 - m.b1571 <= 0)
m.c85 = Constraint(expr= m.x180 - m.b1572 <= 0)
m.c86 = Constraint(expr= m.x181 - m.b1573 <= 0)
m.c87 = Constraint(expr= m.x182 - m.b1568 <= 0)
m.c88 = Constraint(expr= m.x183 - m.b1569 <= 0)
m.c89 = Constraint(expr= m.x184 - m.b1570 <= 0)
m.c90 = Constraint(expr= m.x185 - m.b1571 <= 0)
m.c91 = Constraint(expr= m.x186 - m.b1572 <= 0)
m.c92 = Constraint(expr= m.x187 - m.b1573 <= 0)
m.c93 = Constraint(expr= m.x188 - m.b1568 <= 0)
m.c94 = Constraint(expr= m.x189 - m.b1569 <= 0)
m.c95 = Constraint(expr= m.x190 - m.b1570 <= 0)
m.c96 = Constraint(expr= m.x191 - m.b1571 <= 0)
m.c97 = Constraint(expr= m.x192 - m.b1572 <= 0)
m.c98 = Constraint(expr= m.x193 - m.b1573 <= 0)
m.c99 = Constraint(expr= m.x194 - m.b1568 <= 0)
m.c100 = Constraint(expr= m.x195 - m.b1569 <= 0)
m.c101 = Constraint(expr= m.x196 - m.b1570 <= 0)
m.c102 = Constraint(expr= m.x197 - m.b1571 <= 0)
m.c103 = Constraint(expr= m.x198 - m.b1572 <= 0)
m.c104 = Constraint(expr= m.x199 - m.b1573 <= 0)
m.c105 = Constraint(expr= m.x200 - m.b1568 <= 0)
m.c106 = Constraint(expr= m.x201 - m.b1569 <= 0)
m.c107 = Constraint(expr= m.x202 - m.b1570 <= 0)
m.c108 = Constraint(expr= m.x203 - m.b1571 <= 0)
m.c109 = Constraint(expr= m.x204 - m.b1572 <= 0)
m.c110 = Constraint(expr= m.x205 - m.b1573 <= 0)
m.c111 = Constraint(expr= m.x206 - m.b1568 <= 0)
m.c112 = Constraint(expr= m.x207 - m.b1569 <= 0)
m.c113 = Constraint(expr= m.x208 - m.b1570 <= 0)
m.c114 = Constraint(expr= m.x209 - m.b1571 <= 0)
m.c115 = Constraint(expr= m.x210 - m.b1572 <= 0)
m.c116 = Constraint(expr= m.x211 - m.b1573 <= 0)
m.c117 = Constraint(expr= m.x212 - m.b1568 <= 0)
m.c118 = Constraint(expr= m.x213 - m.b1569 <= 0)
m.c119 = Constraint(expr= m.x214 - m.b1570 <= 0)
m.c120 = Constraint(expr= m.x215 - m.b1571 <= 0)
m.c121 = Constraint(expr= m.x216 - m.b1572 <= 0)
m.c122 = Constraint(expr= m.x217 - m.b1573 <= 0)
m.c123 = Constraint(expr= m.x218 - m.b1568 <= 0)
m.c124 = Constraint(expr= m.x219 - m.b1569 <= 0)
m.c125 = Constraint(expr= m.x220 - m.b1570 <= 0)
m.c126 = Constraint(expr= m.x221 - m.b1571 <= 0)
m.c127 = Constraint(expr= m.x222 - m.b1572 <= 0)
m.c128 = Constraint(expr= m.x223 - m.b1573 <= 0)
m.c129 = Constraint(expr= m.x224 - m.b1574 <= 0)
m.c130 = Constraint(expr= m.x230 - m.b1574 <= 0)
m.c131 = Constraint(expr= m.x231 - m.b1575 <= 0)
m.c132 = Constraint(expr= m.x236 - m.b1574 <= 0)
m.c133 = Constraint(expr= m.x237 - m.b1575 <= 0)
m.c134 = Constraint(expr= m.x238 - m.b1576 <= 0)
m.c135 = Constraint(expr= m.x242 - m.b1574 <= 0)
m.c136 = Constraint(expr= m.x243 - m.b1575 <= 0)
m.c137 = Constraint(expr= m.x244 - m.b1576 <= 0)
m.c138 = Constraint(expr= m.x245 - m.b1577 <= 0)
m.c139 = Constraint(expr= m.x248 - m.b1574 <= 0)
m.c140 = Constraint(expr= m.x249 - m.b1575 <= 0)
m.c141 = Constraint(expr= m.x250 - m.b1576 <= 0)
m.c142 = Constraint(expr= m.x251 - m.b1577 <= 0)
m.c143 = Constraint(expr= m.x252 - m.b1578 <= 0)
m.c144 = Constraint(expr= m.x253 - m.b1579 <= 0)
m.c145 = Constraint(expr= m.x254 - m.b1580 <= 0)
m.c146 = Constraint(expr= m.x255 - m.b1581 <= 0)
m.c147 = Constraint(expr= m.x260 - m.b1580 <= 0)
m.c148 = Constraint(expr= m.x261 - m.b1581 <= 0)
m.c149 = Constraint(expr= m.x262 - m.b1582 <= 0)
m.c150 = Constraint(expr= m.x266 - m.b1580 <= 0)
m.c151 = Constraint(expr= m.x267 - m.b1581 <= 0)
m.c152 = Constraint(expr= m.x268 - m.b1582 <= 0)
m.c153 = Constraint(expr= m.x269 - m.b1583 <= 0)
m.c154 = Constraint(expr= m.x270 - m.b1584 <= 0)
m.c155 = Constraint(expr= m.x271 - m.b1585 <= 0)
m.c156 = Constraint(expr= m.x272 - m.b1580 <= 0)
m.c157 = Constraint(expr= m.x273 - m.b1581 <= 0)
m.c158 = Constraint(expr= m.x274 - m.b1582 <= 0)
m.c159 = Constraint(expr= m.x275 - m.b1583 <= 0)
m.c160 = Constraint(expr= m.x276 - m.b1584 <= 0)
m.c161 = Constraint(expr= m.x277 - m.b1585 <= 0)
m.c162 = Constraint(expr= m.x278 - m.b1580 <= 0)
m.c163 = Constraint(expr= m.x279 - m.b1581 <= 0)
m.c164 = Constraint(expr= m.x280 - m.b1582 <= 0)
m.c165 = Constraint(expr= m.x281 - m.b1583 <= 0)
m.c166 = Constraint(expr= m.x282 - m.b1584 <= 0)
m.c167 = Constraint(expr= m.x283 - m.b1585 <= 0)
m.c168 = Constraint(expr= m.x284 - m.b1580 <= 0)
m.c169 = Constraint(expr= m.x285 - m.b1581 <= 0)
m.c170 = Constraint(expr= m.x286 - m.b1582 <= 0)
m.c171 = Constraint(expr= m.x287 - m.b1583 <= 0)
m.c172 = Constraint(expr= m.x288 - m.b1584 <= 0)
m.c173 = Constraint(expr= m.x289 - m.b1585 <= 0)
m.c174 = Constraint(expr= m.x290 - m.b1580 <= 0)
m.c175 = Constraint(expr= m.x291 - m.b1581 <= 0)
m.c176 = Constraint(expr= m.x292 - m.b1582 <= 0)
m.c177 = Constraint(expr= m.x293 - m.b1583 <= 0)
m.c178 = Constraint(expr= m.x294 - m.b1584 <= 0)
m.c179 = Constraint(expr= m.x295 - m.b1585 <= 0)
m.c180 = Constraint(expr= m.x296 - m.b1580 <= 0)
m.c181 = Constraint(expr= m.x297 - m.b1581 <= 0)
m.c182 = Constraint(expr= m.x298 - m.b1582 <= 0)
m.c183 = Constraint(expr= m.x299 - m.b1583 <= 0)
m.c184 = Constraint(expr= m.x300 - m.b1584 <= 0)
m.c185 = Constraint(expr= m.x301 - m.b1585 <= 0)
m.c186 = Constraint(expr= m.x302 - m.b1586 <= 0)
m.c187 = Constraint(expr= m.x308 - m.b1586 <= 0)
m.c188 = Constraint(expr= m.x309 - m.b1587 <= 0)
m.c189 = Constraint(expr= m.x314 - m.b1586 <= 0)
m.c190 = Constraint(expr= m.x315 - m.b1587 <= 0)
m.c191 = Constraint(expr= m.x316 - m.b1588 <= 0)
m.c192 = Constraint(expr= m.x320 - m.b1586 <= 0)
m.c193 = Constraint(expr= m.x321 - m.b1587 <= 0)
m.c194 = Constraint(expr= m.x322 - m.b1588 <= 0)
m.c195 = Constraint(expr= m.x323 - m.b1589 <= 0)
m.c196 = Constraint(expr= m.x324 - m.b1590 <= 0)
m.c197 = Constraint(expr= m.x325 - m.b1591 <= 0)
m.c198 = Constraint(expr= m.x326 - m.b1586 <= 0)
m.c199 = Constraint(expr= m.x327 - m.b1587 <= 0)
m.c200 = Constraint(expr= m.x328 - m.b1588 <= 0)
m.c201 = Constraint(expr= m.x329 - m.b1589 <= 0)
m.c202 = Constraint(expr= m.x330 - m.b1590 <= 0)
m.c203 = Constraint(expr= m.x331 - m.b1591 <= 0)
m.c204 = Constraint(expr= m.x332 - m.b1586 <= 0)
m.c205 = Constraint(expr= m.x333 - m.b1587 <= 0)
m.c206 = Constraint(expr= m.x334 - m.b1588 <= 0)
m.c207 = Constraint(expr= m.x335 - m.b1589 <= 0)
m.c208 = Constraint(expr= m.x336 - m.b1590 <= 0)
m.c209 = Constraint(expr= m.x337 - m.b1591 <= 0)
m.c210 = Constraint(expr= m.x338 - m.b1586 <= 0)
m.c211 = Constraint(expr= m.x339 - m.b1587 <= 0)
m.c212 = Constraint(expr= m.x340 - m.b1588 <= 0)
m.c213 = Constraint(expr= m.x341 - m.b1589 <= 0)
m.c214 = Constraint(expr= m.x342 - m.b1590 <= 0)
m.c215 = Constraint(expr= m.x343 - m.b1591 <= 0)
m.c216 = Constraint(expr= m.x344 - m.b1586 <= 0)
m.c217 = Constraint(expr= m.x345 - m.b1587 <= 0)
m.c218 = Constraint(expr= m.x346 - m.b1588 <= 0)
m.c219 = Constraint(expr= m.x347 - m.b1589 <= 0)
m.c220 = Constraint(expr= m.x348 - m.b1590 <= 0)
m.c221 = Constraint(expr= m.x349 - m.b1591 <= 0)
m.c222 = Constraint(expr= m.x350 - m.b1586 <= 0)
m.c223 = Constraint(expr= m.x351 - m.b1587 <= 0)
m.c224 = Constraint(expr= m.x352 - m.b1588 <= 0)
m.c225 = Constraint(expr= m.x353 - m.b1589 <= 0)
m.c226 = Constraint(expr= m.x354 - m.b1590 <= 0)
m.c227 = Constraint(expr= m.x355 - m.b1591 <= 0)
m.c228 = Constraint(expr= m.x356 - m.b1586 <= 0)
m.c229 = Constraint(expr= m.x357 - m.b1587 <= 0)
m.c230 = Constraint(expr= m.x358 - m.b1588 <= 0)
m.c231 = Constraint(expr= m.x359 - m.b1589 <= 0)
m.c232 = Constraint(expr= m.x360 - m.b1590 <= 0)
m.c233 = Constraint(expr= m.x361 - m.b1591 <= 0)
m.c234 = Constraint(expr= m.x362 - m.b1592 <= 0)
m.c235 = Constraint(expr= m.x363 - m.b1593 <= 0)
m.c236 = Constraint(expr= m.x368 - m.b1592 <= 0)
m.c237 = Constraint(expr= m.x369 - m.b1593 <= 0)
m.c238 = Constraint(expr= m.x370 - m.b1594 <= 0)
m.c239 = Constraint(expr= m.x374 - m.b1592 <= 0)
m.c240 = Constraint(expr= m.x375 - m.b1593 <= 0)
m.c241 = Constraint(expr= m.x376 - m.b1594 <= 0)
m.c242 = Constraint(expr= m.x377 - m.b1595 <= 0)
m.c243 = Constraint(expr= m.x378 - m.b1596 <= 0)
m.c244 = Constraint(expr= m.x379 - m.b1597 <= 0)
m.c245 = Constraint(expr= m.x380 - m.b1592 <= 0)
m.c246 = Constraint(expr= m.x381 - m.b1593 <= 0)
m.c247 = Constraint(expr= m.x382 - m.b1594 <= 0)
m.c248 = Constraint(expr= m.x383 - m.b1595 <= 0)
m.c249 = Constraint(expr= m.x384 - m.b1596 <= 0)
m.c250 = Constraint(expr= m.x385 - m.b1597 <= 0)
m.c251 = Constraint(expr= m.x386 - m.b1592 <= 0)
m.c252 = Constraint(expr= m.x387 - m.b1593 <= 0)
m.c253 = Constraint(expr= m.x388 - m.b1594 <= 0)
m.c254 = Constraint(expr= m.x389 - m.b1595 <= 0)
m.c255 = Constraint(expr= m.x390 - m.b1596 <= 0)
m.c256 = Constraint(expr= m.x391 - m.b1597 <= 0)
m.c257 = Constraint(expr= m.x392 - m.b1592 <= 0)
m.c258 = Constraint(expr= m.x393 - m.b1593 <= 0)
m.c259 = Constraint(expr= m.x394 - m.b1594 <= 0)
m.c260 = Constraint(expr= m.x395 - m.b1595 <= 0)
m.c261 = Constraint(expr= m.x396 - m.b1596 <= 0)
m.c262 = Constraint(expr= m.x397 - m.b1597 <= 0)
m.c263 = Constraint(expr= m.x398 - m.b1592 <= 0)
m.c264 = Constraint(expr= m.x399 - m.b1593 <= 0)
m.c265 = Constraint(expr= m.x400 - m.b1594 <= 0)
m.c266 = Constraint(expr= m.x401 - m.b1595 <= 0)
m.c267 = Constraint(expr= m.x402 - m.b1596 <= 0)
m.c268 = Constraint(expr= m.x403 - m.b1597 <= 0)
m.c269 = Constraint(expr= m.x404 - m.b1592 <= 0)
m.c270 = Constraint(expr= m.x405 - m.b1593 <= 0)
m.c271 = Constraint(expr= m.x406 - m.b1594 <= 0)
m.c272 = Constraint(expr= m.x407 - m.b1595 <= 0)
m.c273 = Constraint(expr= m.x408 - m.b1596 <= 0)
m.c274 = Constraint(expr= m.x409 - m.b1597 <= 0)
m.c275 = Constraint(expr= m.x410 - m.b1598 <= 0)
m.c276 = Constraint(expr= m.x411 - m.b1599 <= 0)
m.c277 = Constraint(expr= m.x416 - m.b1598 <= 0)
m.c278 = Constraint(expr= m.x417 - m.b1599 <= 0)
m.c279 = Constraint(expr= m.x418 - m.b1600 <= 0)
m.c280 = Constraint(expr= m.x422 - m.b1598 <= 0)
m.c281 = Constraint(expr= m.x423 - m.b1599 <= 0)
m.c282 = Constraint(expr= m.x424 - m.b1600 <= 0)
m.c283 = Constraint(expr= m.x425 - m.b1601 <= 0)
m.c284 = Constraint(expr= m.x426 - m.b1602 <= 0)
m.c285 = Constraint(expr= m.x427 - m.b1603 <= 0)
m.c286 = Constraint(expr= m.x428 - m.b1598 <= 0)
m.c287 = Constraint(expr= m.x429 - m.b1599 <= 0)
m.c288 = Constraint(expr= m.x430 - m.b1600 <= 0)
m.c289 = Constraint(expr= m.x431 - m.b1601 <= 0)
m.c290 = Constraint(expr= m.x432 - m.b1602 <= 0)
m.c291 = Constraint(expr= m.x433 - m.b1603 <= 0)
m.c292 = Constraint(expr= m.x434 - m.b1598 <= 0)
m.c293 = Constraint(expr= m.x435 - m.b1599 <= 0)
m.c294 = Constraint(expr= m.x436 - m.b1600 <= 0)
m.c295 = Constraint(expr= m.x437 - m.b1601 <= 0)
m.c296 = Constraint(expr= m.x438 - m.b1602 <= 0)
m.c297 = Constraint(expr= m.x439 - m.b1603 <= 0)
m.c298 = Constraint(expr= m.x440 - m.b1598 <= 0)
m.c299 = Constraint(expr= m.x441 - m.b1599 <= 0)
m.c300 = Constraint(expr= m.x442 - m.b1600 <= 0)
m.c301 = Constraint(expr= m.x443 - m.b1601 <= 0)
m.c302 = Constraint(expr= m.x444 - m.b1602 <= 0)
m.c303 = Constraint(expr= m.x445 - m.b1603 <= 0)
m.c304 = Constraint(expr= m.x446 - m.b1598 <= 0)
m.c305 = Constraint(expr= m.x447 - m.b1599 <= 0)
m.c306 = Constraint(expr= m.x448 - m.b1600 <= 0)
m.c307 = Constraint(expr= m.x449 - m.b1601 <= 0)
m.c308 = Constraint(expr= m.x450 - m.b1602 <= 0)
m.c309 = Constraint(expr= m.x451 - m.b1603 <= 0)
m.c310 = Constraint(expr= m.x452 - m.b1598 <= 0)
m.c311 = Constraint(expr= m.x453 - m.b1599 <= 0)
m.c312 = Constraint(expr= m.x454 - m.b1600 <= 0)
m.c313 = Constraint(expr= m.x455 - m.b1601 <= 0)
m.c314 = Constraint(expr= m.x456 - m.b1602 <= 0)
m.c315 = Constraint(expr= m.x457 - m.b1603 <= 0)
m.c316 = Constraint(expr= m.x458 - m.b1598 <= 0)
m.c317 = Constraint(expr= m.x459 - m.b1599 <= 0)
m.c318 = Constraint(expr= m.x460 - m.b1600 <= 0)
m.c319 = Constraint(expr= m.x461 - m.b1601 <= 0)
m.c320 = Constraint(expr= m.x462 - m.b1602 <= 0)
m.c321 = Constraint(expr= m.x463 - m.b1603 <= 0)
m.c322 = Constraint(expr= m.x464 - m.b1598 <= 0)
m.c323 = Constraint(expr= m.x465 - m.b1599 <= 0)
m.c324 = Constraint(expr= m.x466 - m.b1600 <= 0)
m.c325 = Constraint(expr= m.x467 - m.b1601 <= 0)
m.c326 = Constraint(expr= m.x468 - m.b1602 <= 0)
m.c327 = Constraint(expr= m.x469 - m.b1603 <= 0)
m.c328 = Constraint(expr= m.x470 - m.b1604 <= 0)
m.c329 = Constraint(expr= m.x476 - m.b1604 <= 0)
m.c330 = Constraint(expr= m.x477 - m.b1605 <= 0)
m.c331 = Constraint(expr= m.x478 - m.b1606 <= 0)
m.c332 = Constraint(expr= m.x479 - m.b1607 <= 0)
m.c333 = Constraint(expr= m.x480 - m.b1608 <= 0)
m.c334 = Constraint(expr= m.x481 - m.b1609 <= 0)
m.c335 = Constraint(expr= m.x482 - m.b1610 <= 0)
m.c336 = Constraint(expr= m.x488 - m.b1610 <= 0)
m.c337 = Constraint(expr= m.x489 - m.b1611 <= 0)
m.c338 = Constraint(expr= m.x490 - m.b1612 <= 0)
m.c339 = Constraint(expr= m.x491 - m.b1613 <= 0)
m.c340 = Constraint(expr= m.x492 - m.b1614 <= 0)
m.c341 = Constraint(expr= m.x494 - m.b1610 <= 0)
m.c342 = Constraint(expr= m.x495 - m.b1611 <= 0)
m.c343 = Constraint(expr= m.x496 - m.b1612 <= 0)
m.c344 = Constraint(expr= m.x497 - m.b1613 <= 0)
m.c345 = Constraint(expr= m.x498 - m.b1614 <= 0)
m.c346 = Constraint(expr= m.x499 - m.b1615 <= 0)
m.c347 = Constraint(expr= m.x500 - m.b1610 <= 0)
m.c348 = Constraint(expr= m.x501 - m.b1611 <= 0)
m.c349 = Constraint(expr= m.x502 - m.b1612 <= 0)
m.c350 = Constraint(expr= m.x503 - m.b1613 <= 0)
m.c351 = Constraint(expr= m.x504 - m.b1614 <= 0)
m.c352 = Constraint(expr= m.x505 - m.b1615 <= 0)
m.c353 = Constraint(expr= m.x506 - m.b1616 <= 0)
m.c354 = Constraint(expr= m.x507 - m.b1617 <= 0)
m.c355 = Constraint(expr= m.x508 - m.b1618 <= 0)
m.c356 = Constraint(expr= m.x509 - m.b1619 <= 0)
m.c357 = Constraint(expr= m.x510 - m.b1620 <= 0)
m.c358 = Constraint(expr= m.x512 - m.b1616 <= 0)
m.c359 = Constraint(expr= m.x513 - m.b1617 <= 0)
m.c360 = Constraint(expr= m.x514 - m.b1618 <= 0)
m.c361 = Constraint(expr= m.x515 - m.b1619 <= 0)
m.c362 = Constraint(expr= m.x516 - m.b1620 <= 0)
m.c363 = Constraint(expr= m.x517 - m.b1621 <= 0)
m.c364 = Constraint(expr= m.x518 - m.b1622 <= 0)
m.c365 = Constraint(expr= m.x519 - m.b1623 <= 0)
m.c366 = Constraint(expr= m.x524 - m.b1622 <= 0)
m.c367 = Constraint(expr= m.x525 - m.b1623 <= 0)
m.c368 = Constraint(expr= m.x526 - m.b1624 <= 0)
m.c369 = Constraint(expr= m.x530 - m.b1622 <= 0)
m.c370 = Constraint(expr= m.x531 - m.b1623 <= 0)
m.c371 = Constraint(expr= m.x532 - m.b1624 <= 0)
m.c372 = Constraint(expr= m.x533 - m.b1625 <= 0)
m.c373 = Constraint(expr= m.x534 - m.b1626 <= 0)
m.c374 = Constraint(expr= m.x535 - m.b1627 <= 0)
m.c375 = Constraint(expr= m.x536 - m.b1628 <= 0)
m.c376 = Constraint(expr= m.x537 - m.b1629 <= 0)
m.c377 = Constraint(expr= m.x542 - m.b1628 <= 0)
m.c378 = Constraint(expr= m.x543 - m.b1629 <= 0)
m.c379 = Constraint(expr= m.x544 - m.b1630 <= 0)
m.c380 = Constraint(expr= m.x548 - m.b1628 <= 0)
m.c381 = Constraint(expr= m.x549 - m.b1629 <= 0)
m.c382 = Constraint(expr= m.x550 - m.b1630 <= 0)
m.c383 = Constraint(expr= m.x551 - m.b1631 <= 0)
m.c384 = Constraint(expr= m.x552 - m.b1632 <= 0)
m.c385 = Constraint(expr= m.x553 - m.b1633 <= 0)
m.c386 = Constraint(expr= m.x554 - m.b1628 <= 0)
m.c387 = Constraint(expr= m.x555 - m.b1629 <= 0)
m.c388 = Constraint(expr= m.x556 - m.b1630 <= 0)
m.c389 = Constraint(expr= m.x557 - m.b1631 <= 0)
m.c390 = Constraint(expr= m.x558 - m.b1632 <= 0)
m.c391 = Constraint(expr= m.x559 - m.b1633 <= 0)
m.c392 = Constraint(expr= m.x560 - m.b1634 <= 0)
m.c393 = Constraint(expr= m.x561 - m.b1635 <= 0)
m.c394 = Constraint(expr= m.x566 - m.b1634 <= 0)
m.c395 = Constraint(expr= m.x567 - m.b1635 <= 0)
m.c396 = Constraint(expr= m.x568 - m.b1636 <= 0)
m.c397 = Constraint(expr= m.x572 - m.b1634 <= 0)
m.c398 = Constraint(expr= m.x573 - m.b1635 <= 0)
m.c399 = Constraint(expr= m.x574 - m.b1636 <= 0)
m.c400 = Constraint(expr= m.x575 - m.b1637 <= 0)
m.c401 = Constraint(expr= m.x576 - m.b1638 <= 0)
m.c402 = Constraint(expr= m.x577 - m.b1639 <= 0)
m.c403 = Constraint(expr= m.x578 - m.b1634 <= 0)
m.c404 = Constraint(expr= m.x579 - m.b1635 <= 0)
m.c405 = Constraint(expr= m.x580 - m.b1636 <= 0)
m.c406 = Constraint(expr= m.x581 - m.b1637 <= 0)
m.c407 = Constraint(expr= m.x582 - m.b1638 <= 0)
m.c408 = Constraint(expr= m.x583 - m.b1639 <= 0)
m.c409 = Constraint(expr= m.x584 - m.b1634 <= 0)
m.c410 = Constraint(expr= m.x585 - m.b1635 <= 0)
m.c411 = Constraint(expr= m.x586 - m.b1636 <= 0)
m.c412 = Constraint(expr= m.x587 - m.b1637 <= 0)
m.c413 = Constraint(expr= m.x588 - m.b1638 <= 0)
m.c414 = Constraint(expr= m.x589 - m.b1639 <= 0)
m.c415 = Constraint(expr= m.x590 - m.b1634 <= 0)
m.c416 = Constraint(expr= m.x591 - m.b1635 <= 0)
m.c417 = Constraint(expr= m.x592 - m.b1636 <= 0)
m.c418 = Constraint(expr= m.x593 - m.b1637 <= 0)
m.c419 = Constraint(expr= m.x594 - m.b1638 <= 0)
m.c420 = Constraint(expr= m.x595 - m.b1639 <= 0)
m.c421 = Constraint(expr= m.x596 - m.b1646 <= 0)
m.c422 = Constraint(expr= m.x597 - m.b1647 <= 0)
m.c423 = Constraint(expr= m.x602 - m.b1646 <= 0)
m.c424 = Constraint(expr= m.x603 - m.b1647 <= 0)
m.c425 = Constraint(expr= m.x604 - m.b1648 <= 0)
m.c426 = Constraint(expr= m.x605 - m.b1649 <= 0)
m.c427 = Constraint(expr= m.x606 - m.b1650 <= 0)
m.c428 = Constraint(expr= m.x607 - m.b1651 <= 0)
m.c429 = Constraint(expr= m.x608 - m.b1646 <= 0)
m.c430 = Constraint(expr= m.x609 - m.b1647 <= 0)
m.c431 = Constraint(expr= m.x610 - m.b1648 <= 0)
m.c432 = Constraint(expr= m.x611 - m.b1649 <= 0)
m.c433 = Constraint(expr= m.x612 - m.b1650 <= 0)
m.c434 = Constraint(expr= m.x613 - m.b1651 <= 0)
m.c435 = Constraint(expr= m.x614 - m.b1646 <= 0)
m.c436 = Constraint(expr= m.x615 - m.b1647 <= 0)
m.c437 = Constraint(expr= m.x616 - m.b1648 <= 0)
m.c438 = Constraint(expr= m.x617 - m.b1649 <= 0)
m.c439 = Constraint(expr= m.x618 - m.b1650 <= 0)
m.c440 = Constraint(expr= m.x619 - m.b1651 <= 0)
m.c441 = Constraint(expr= m.x620 - m.b1646 <= 0)
m.c442 = Constraint(expr= m.x621 - m.b1647 <= 0)
m.c443 = Constraint(expr= m.x622 - m.b1648 <= 0)
m.c444 = Constraint(expr= m.x623 - m.b1649 <= 0)
m.c445 = Constraint(expr= m.x624 - m.b1650 <= 0)
m.c446 = Constraint(expr= m.x625 - m.b1651 <= 0)
m.c447 = Constraint(expr= m.x626 - m.b1646 <= 0)
m.c448 = Constraint(expr= m.x627 - m.b1647 <= 0)
m.c449 = Constraint(expr= m.x628 - m.b1648 <= 0)
m.c450 = Constraint(expr= m.x629 - m.b1649 <= 0)
m.c451 = Constraint(expr= m.x630 - m.b1650 <= 0)
m.c452 = Constraint(expr= m.x631 - m.b1651 <= 0)
m.c453 = Constraint(expr= m.x632 - m.b1646 <= 0)
m.c454 = Constraint(expr= m.x633 - m.b1647 <= 0)
m.c455 = Constraint(expr= m.x634 - m.b1648 <= 0)
m.c456 = Constraint(expr= m.x635 - m.b1649 <= 0)
m.c457 = Constraint(expr= m.x636 - m.b1650 <= 0)
m.c458 = Constraint(expr= m.x637 - m.b1651 <= 0)
m.c459 = Constraint(expr= m.x638 - m.b1646 <= 0)
m.c460 = Constraint(expr= m.x639 - m.b1647 <= 0)
m.c461 = Constraint(expr= m.x640 - m.b1648 <= 0)
m.c462 = Constraint(expr= m.x641 - m.b1649 <= 0)
m.c463 = Constraint(expr= m.x642 - m.b1650 <= 0)
m.c464 = Constraint(expr= m.x643 - m.b1651 <= 0)
m.c465 = Constraint(expr= m.x644 - m.b1646 <= 0)
m.c466 = Constraint(expr= m.x645 - m.b1647 <= 0)
m.c467 = Constraint(expr= m.x646 - m.b1648 <= 0)
m.c468 = Constraint(expr= m.x647 - m.b1649 <= 0)
m.c469 = Constraint(expr= m.x648 - m.b1650 <= 0)
m.c470 = Constraint(expr= m.x649 - m.b1651 <= 0)
m.c471 = Constraint(expr= m.x650 - m.b1652 <= 0)
m.c472 = Constraint(expr= m.x656 - m.b1652 <= 0)
m.c473 = Constraint(expr= m.x657 - m.b1653 <= 0)
m.c474 = Constraint(expr= m.x662 - m.b1652 <= 0)
m.c475 = Constraint(expr= m.x663 - m.b1653 <= 0)
m.c476 = Constraint(expr= m.x664 - m.b1654 <= 0)
m.c477 = Constraint(expr= m.x665 - m.b1655 <= 0)
m.c478 = Constraint(expr= m.x668 - m.b1652 <= 0)
m.c479 = Constraint(expr= m.x669 - m.b1653 <= 0)
m.c480 = Constraint(expr= m.x670 - m.b1654 <= 0)
m.c481 = Constraint(expr= m.x671 - m.b1655 <= 0)
m.c482 = Constraint(expr= m.x672 - m.b1656 <= 0)
m.c483 = Constraint(expr= m.x674 - m.b1652 <= 0)
m.c484 = Constraint(expr= m.x675 - m.b1653 <= 0)
m.c485 = Constraint(expr= m.x676 - m.b1654 <= 0)
m.c486 = Constraint(expr= m.x677 - m.b1655 <= 0)
m.c487 = Constraint(expr= m.x678 - m.b1656 <= 0)
m.c488 = Constraint(expr= m.x679 - m.b1657 <= 0)
m.c489 = Constraint(expr= m.x680 - m.b1652 <= 0)
m.c490 = Constraint(expr= m.x681 - m.b1653 <= 0)
m.c491 = Constraint(expr= m.x682 - m.b1654 <= 0)
m.c492 = Constraint(expr= m.x683 - m.b1655 <= 0)
m.c493 = Constraint(expr= m.x684 - m.b1656 <= 0)
m.c494 = Constraint(expr= m.x685 - m.b1657 <= 0)
m.c495 = Constraint(expr= m.x686 - m.b1658 <= 0)
m.c496 = Constraint(expr= m.x692 - m.b1658 <= 0)
m.c497 = Constraint(expr= m.x693 - m.b1659 <= 0)
m.c498 = Constraint(expr= m.x698 - m.b1658 <= 0)
m.c499 = Constraint(expr= m.x699 - m.b1659 <= 0)
m.c500 = Constraint(expr= m.x700 - m.b1660 <= 0)
m.c501 = Constraint(expr= m.x701 - m.b1661 <= 0)
m.c502 = Constraint(expr= m.x704 - m.b1658 <= 0)
m.c503 = Constraint(expr= m.x705 - m.b1659 <= 0)
m.c504 = Constraint(expr= m.x706 - m.b1660 <= 0)
m.c505 = Constraint(expr= m.x707 - m.b1661 <= 0)
m.c506 = Constraint(expr= m.x708 - m.b1662 <= 0)
m.c507 = Constraint(expr= m.x710 - m.b1658 <= 0)
m.c508 = Constraint(expr= m.x711 - m.b1659 <= 0)
m.c509 = Constraint(expr= m.x712 - m.b1660 <= 0)
m.c510 = Constraint(expr= m.x713 - m.b1661 <= 0)
m.c511 = Constraint(expr= m.x714 - m.b1662 <= 0)
m.c512 = Constraint(expr= m.x715 - m.b1663 <= 0)
m.c513 = Constraint(expr= m.x716 - m.b1658 <= 0)
m.c514 = Constraint(expr= m.x717 - m.b1659 <= 0)
m.c515 = Constraint(expr= m.x718 - m.b1660 <= 0)
m.c516 = Constraint(expr= m.x719 - m.b1661 <= 0)
m.c517 = Constraint(expr= m.x720 - m.b1662 <= 0)
m.c518 = Constraint(expr= m.x721 - m.b1663 <= 0)
m.c519 = Constraint(expr= m.x722 - m.b1658 <= 0)
m.c520 = Constraint(expr= m.x723 - m.b1659 <= 0)
m.c521 = Constraint(expr= m.x724 - m.b1660 <= 0)
m.c522 = Constraint(expr= m.x725 - m.b1661 <= 0)
m.c523 = Constraint(expr= m.x726 - m.b1662 <= 0)
m.c524 = Constraint(expr= m.x727 - m.b1663 <= 0)
m.c525 = Constraint(expr= m.x728 - m.b1664 <= 0)
m.c526 = Constraint(expr= m.x734 - m.b1664 <= 0)
m.c527 = Constraint(expr= m.x735 - m.b1665 <= 0)
m.c528 = Constraint(expr= m.x736 - m.b1666 <= 0)
m.c529 = Constraint(expr= m.x737 - m.b1667 <= 0)
m.c530 = Constraint(expr= m.x740 - m.b1664 <= 0)
m.c531 = Constraint(expr= m.x741 - m.b1665 <= 0)
m.c532 = Constraint(expr= m.x742 - m.b1666 <= 0)
m.c533 = Constraint(expr= m.x743 - m.b1667 <= 0)
m.c534 = Constraint(expr= m.x744 - m.b1668 <= 0)
m.c535 = Constraint(expr= m.x746 - m.b1664 <= 0)
m.c536 = Constraint(expr= m.x747 - m.b1665 <= 0)
m.c537 = Constraint(expr= m.x748 - m.b1666 <= 0)
m.c538 = Constraint(expr= m.x749 - m.b1667 <= 0)
m.c539 = Constraint(expr= m.x750 - m.b1668 <= 0)
m.c540 = Constraint(expr= m.x751 - m.b1669 <= 0)
m.c541 = Constraint(expr= m.x752 - m.b1664 <= 0)
m.c542 = Constraint(expr= m.x753 - m.b1665 <= 0)
m.c543 = Constraint(expr= m.x754 - m.b1666 <= 0)
m.c544 = Constraint(expr= m.x755 - m.b1667 <= 0)
m.c545 = Constraint(expr= m.x756 - m.b1668 <= 0)
m.c546 = Constraint(expr= m.x757 - m.b1669 <= 0)
m.c547 = Constraint(expr= m.x758 - m.b1664 <= 0)
m.c548 = Constraint(expr= m.x759 - m.b1665 <= 0)
m.c549 = Constraint(expr= m.x760 - m.b1666 <= 0)
m.c550 = Constraint(expr= m.x761 - m.b1667 <= 0)
m.c551 = Constraint(expr= m.x762 - m.b1668 <= 0)
m.c552 = Constraint(expr= m.x763 - m.b1669 <= 0)
m.c553 = Constraint(expr= m.x764 - m.b1664 <= 0)
m.c554 = Constraint(expr= m.x765 - m.b1665 <= 0)
m.c555 = Constraint(expr= m.x766 - m.b1666 <= 0)
m.c556 = Constraint(expr= m.x767 - m.b1667 <= 0)
m.c557 = Constraint(expr= m.x768 - m.b1668 <= 0)
m.c558 = Constraint(expr= m.x769 - m.b1669 <= 0)
m.c559 = Constraint(expr= m.x770 - m.b1664 <= 0)
m.c560 = Constraint(expr= m.x771 - m.b1665 <= 0)
m.c561 = Constraint(expr= m.x772 - m.b1666 <= 0)
m.c562 = Constraint(expr= m.x773 - m.b1667 <= 0)
m.c563 = Constraint(expr= m.x774 - m.b1668 <= 0)
m.c564 = Constraint(expr= m.x775 - m.b1669 <= 0)
m.c565 = Constraint(expr= m.x776 - m.b1676 <= 0)
m.c566 = Constraint(expr= m.x777 - m.b1677 <= 0)
m.c567 = Constraint(expr= m.x782 - m.b1676 <= 0)
m.c568 = Constraint(expr= m.x783 - m.b1677 <= 0)
m.c569 = Constraint(expr= m.x784 - m.b1678 <= 0)
m.c570 = Constraint(expr= m.x785 - m.b1679 <= 0)
m.c571 = Constraint(expr= m.x786 - m.b1680 <= 0)
m.c572 = Constraint(expr= m.x787 - m.b1681 <= 0)
m.c573 = Constraint(expr= m.x788 - m.b1676 <= 0)
m.c574 = Constraint(expr= m.x789 - m.b1677 <= 0)
m.c575 = Constraint(expr= m.x790 - m.b1678 <= 0)
m.c576 = Constraint(expr= m.x791 - m.b1679 <= 0)
m.c577 = Constraint(expr= m.x792 - m.b1680 <= 0)
m.c578 = Constraint(expr= m.x793 - m.b1681 <= 0)
m.c579 = Constraint(expr= m.x794 - m.b1682 <= 0)
m.c580 = Constraint(expr= m.x800 - m.b1682 <= 0)
m.c581 = Constraint(expr= m.x801 - m.b1683 <= 0)
m.c582 = Constraint(expr= m.x806 - m.b1682 <= 0)
m.c583 = Constraint(expr= m.x807 - m.b1683 <= 0)
m.c584 = Constraint(expr= m.x808 - m.b1684 <= 0)
m.c585 = Constraint(expr= m.x809 - m.b1685 <= 0)
m.c586 = Constraint(expr= m.x812 - m.b1682 <= 0)
m.c587 = Constraint(expr= m.x813 - m.b1683 <= 0)
m.c588 = Constraint(expr= m.x814 - m.b1684 <= 0)
m.c589 = Constraint(expr= m.x815 - m.b1685 <= 0)
m.c590 = Constraint(expr= m.x816 - m.b1686 <= 0)
m.c591 = Constraint(expr= m.x818 - m.b1682 <= 0)
m.c592 = Constraint(expr= m.x819 - m.b1683 <= 0)
m.c593 = Constraint(expr= m.x820 - m.b1684 <= 0)
m.c594 = Constraint(expr= m.x821 - m.b1685 <= 0)
m.c595 = Constraint(expr= m.x822 - m.b1686 <= 0)
m.c596 = Constraint(expr= m.x823 - m.b1687 <= 0)
m.c597 = Constraint(expr= m.x824 - m.b1682 <= 0)
m.c598 = Constraint(expr= m.x825 - m.b1683 <= 0)
m.c599 = Constraint(expr= m.x826 - m.b1684 <= 0)
m.c600 = Constraint(expr= m.x827 - m.b1685 <= 0)
m.c601 = Constraint(expr= m.x828 - m.b1686 <= 0)
m.c602 = Constraint(expr= m.x829 - m.b1687 <= 0)
m.c603 = Constraint(expr= m.x830 - m.b1682 <= 0)
m.c604 = Constraint(expr= m.x831 - m.b1683 <= 0)
m.c605 = Constraint(expr= m.x832 - m.b1684 <= 0)
m.c606 = Constraint(expr= m.x833 - m.b1685 <= 0)
m.c607 = Constraint(expr= m.x834 - m.b1686 <= 0)
m.c608 = Constraint(expr= m.x835 - m.b1687 <= 0)
m.c609 = Constraint(expr= m.x836 - m.b1682 <= 0)
m.c610 = Constraint(expr= m.x837 - m.b1683 <= 0)
m.c611 = Constraint(expr= m.x838 - m.b1684 <= 0)
m.c612 = Constraint(expr= m.x839 - m.b1685 <= 0)
m.c613 = Constraint(expr= m.x840 - m.b1686 <= 0)
m.c614 = Constraint(expr= m.x841 - m.b1687 <= 0)
m.c615 = Constraint(expr= m.x842 - m.b1688 <= 0)
m.c616 = Constraint(expr= m.x848 - m.b1688 <= 0)
m.c617 = Constraint(expr= m.x849 - m.b1689 <= 0)
m.c618 = Constraint(expr= m.x850 - m.b1690 <= 0)
m.c619 = Constraint(expr= m.x851 - m.b1691 <= 0)
m.c620 = Constraint(expr= m.x854 - m.b1688 <= 0)
m.c621 = Constraint(expr= m.x855 - m.b1689 <= 0)
m.c622 = Constraint(expr= m.x856 - m.b1690 <= 0)
m.c623 = Constraint(expr= m.x857 - m.b1691 <= 0)
m.c624 = Constraint(expr= m.x858 - m.b1692 <= 0)
m.c625 = Constraint(expr= m.x859 - m.b1693 <= 0)
m.c626 = Constraint(expr= m.x860 - m.b1694 <= 0)
m.c627 = Constraint(expr= m.x861 - m.b1695 <= 0)
m.c628 = Constraint(expr= m.x862 - m.b1696 <= 0)
m.c629 = Constraint(expr= m.x863 - m.b1697 <= 0)
m.c630 = Constraint(expr= m.x864 - m.b1698 <= 0)
m.c631 = Constraint(expr= m.x865 - m.b1699 <= 0)
m.c632 = Constraint(expr= m.x866 - m.b1700 <= 0)
m.c633 = Constraint(expr= m.x867 - m.b1701 <= 0)
m.c634 = Constraint(expr= m.x868 - m.b1702 <= 0)
m.c635 = Constraint(expr= m.x869 - m.b1703 <= 0)
m.c636 = Constraint(expr= m.x870 - m.b1704 <= 0)
m.c637 = Constraint(expr= m.x871 - m.b1705 <= 0)
m.c638 = Constraint(expr= m.x872 - m.b1700 <= 0)
m.c639 = Constraint(expr= m.x873 - m.b1701 <= 0)
m.c640 = Constraint(expr= m.x874 - m.b1702 <= 0)
m.c641 = Constraint(expr= m.x875 - m.b1703 <= 0)
m.c642 = Constraint(expr= m.x876 - m.b1704 <= 0)
m.c643 = Constraint(expr= m.x877 - m.b1705 <= 0)
m.c644 = Constraint(expr= m.x878 - m.b1706 <= 0)
m.c645 = Constraint(expr= m.x879 - m.b1707 <= 0)
m.c646 = Constraint(expr= m.x880 - m.b1708 <= 0)
m.c647 = Constraint(expr= m.x881 - m.b1709 <= 0)
m.c648 = Constraint(expr= m.x882 - m.b1710 <= 0)
m.c649 = Constraint(expr= m.x883 - m.b1711 <= 0)
m.c650 = Constraint(expr= m.x884 - m.b1706 <= 0)
m.c651 = Constraint(expr= m.x885 - m.b1707 <= 0)
m.c652 = Constraint(expr= m.x886 - m.b1708 <= 0)
m.c653 = Constraint(expr= m.x887 - m.b1709 <= 0)
m.c654 = Constraint(expr= m.x888 - m.b1710 <= 0)
m.c655 = Constraint(expr= m.x889 - m.b1711 <= 0)
m.c656 = Constraint(expr= m.x890 - m.b1706 <= 0)
m.c657 = Constraint(expr= m.x891 - m.b1707 <= 0)
m.c658 = Constraint(expr= m.x892 - m.b1708 <= 0)
m.c659 = Constraint(expr= m.x893 - m.b1709 <= 0)
m.c660 = Constraint(expr= m.x894 - m.b1710 <= 0)
m.c661 = Constraint(expr= m.x895 - m.b1711 <= 0)
m.c662 = Constraint(expr= m.x896 - m.b1712 <= 0)
m.c663 = Constraint(expr= m.x897 - m.b1713 <= 0)
m.c664 = Constraint(expr= m.x898 - m.b1714 <= 0)
m.c665 = Constraint(expr= m.x899 - m.b1715 <= 0)
m.c666 = Constraint(expr= m.x900 - m.b1716 <= 0)
m.c667 = Constraint(expr= m.x901 - m.b1717 <= 0)
m.c668 = Constraint(expr= m.x902 - m.b1712 <= 0)
m.c669 = Constraint(expr= m.x903 - m.b1713 <= 0)
m.c670 = Constraint(expr= m.x904 - m.b1714 <= 0)
m.c671 = Constraint(expr= m.x905 - m.b1715 <= 0)
m.c672 = Constraint(expr= m.x906 - m.b1716 <= 0)
m.c673 = Constraint(expr= m.x907 - m.b1717 <= 0)
m.c674 = Constraint(expr= m.x908 - m.b1712 <= 0)
m.c675 = Constraint(expr= m.x909 - m.b1713 <= 0)
m.c676 = Constraint(expr= m.x910 - m.b1714 <= 0)
m.c677 = Constraint(expr= m.x911 - m.b1715 <= 0)
m.c678 = Constraint(expr= m.x912 - m.b1716 <= 0)
m.c679 = Constraint(expr= m.x913 - m.b1717 <= 0)
m.c680 = Constraint(expr= m.x914 - m.b1712 <= 0)
m.c681 = Constraint(expr= m.x915 - m.b1713 <= 0)
m.c682 = Constraint(expr= m.x916 - m.b1714 <= 0)
m.c683 = Constraint(expr= m.x917 - m.b1715 <= 0)
m.c684 = Constraint(expr= m.x918 - m.b1716 <= 0)
m.c685 = Constraint(expr= m.x919 - m.b1717 <= 0)
m.c686 = Constraint(expr= m.x920 - m.b1718 <= 0)
m.c687 = Constraint(expr= m.x921 - m.b1719 <= 0)
m.c688 = Constraint(expr= m.x922 - m.b1720 <= 0)
m.c689 = Constraint(expr= m.x923 - m.b1721 <= 0)
m.c690 = Constraint(expr= m.x924 - m.b1722 <= 0)
m.c691 = Constraint(expr= m.x925 - m.b1723 <= 0)
m.c692 = Constraint(expr= m.x926 - m.b1718 <= 0)
m.c693 = Constraint(expr= m.x927 - m.b1719 <= 0)
m.c694 = Constraint(expr= m.x928 - m.b1720 <= 0)
m.c695 = Constraint(expr= m.x929 - m.b1721 <= 0)
m.c696 = Constraint(expr= m.x930 - m.b1722 <= 0)
m.c697 = Constraint(expr= m.x931 - m.b1723 <= 0)
m.c698 = Constraint(expr= m.x932 - m.b1718 <= 0)
m.c699 = Constraint(expr= m.x933 - m.b1719 <= 0)
m.c700 = Constraint(expr= m.x934 - m.b1720 <= 0)
m.c701 = Constraint(expr= m.x935 - m.b1721 <= 0)
m.c702 = Constraint(expr= m.x936 - m.b1722 <= 0)
m.c703 = Constraint(expr= m.x937 - m.b1723 <= 0)
m.c704 = Constraint(expr= m.x938 - m.b1718 <= 0)
m.c705 = Constraint(expr= m.x939 - m.b1719 <= 0)
m.c706 = Constraint(expr= m.x940 - m.b1720 <= 0)
m.c707 = Constraint(expr= m.x941 - m.b1721 <= 0)
m.c708 = Constraint(expr= m.x942 - m.b1722 <= 0)
m.c709 = Constraint(expr= m.x943 - m.b1723 <= 0)
m.c710 = Constraint(expr= m.x944 - m.b1718 <= 0)
m.c711 = Constraint(expr= m.x945 - m.b1719 <= 0)
m.c712 = Constraint(expr= m.x946 - m.b1720 <= 0)
m.c713 = Constraint(expr= m.x947 - m.b1721 <= 0)
m.c714 = Constraint(expr= m.x948 - m.b1722 <= 0)
m.c715 = Constraint(expr= m.x949 - m.b1723 <= 0)
m.c716 = Constraint(expr= m.x950 - m.b1724 <= 0)
m.c717 = Constraint(expr= m.x951 - m.b1725 <= 0)
m.c718 = Constraint(expr= m.x952 - m.b1726 <= 0)
m.c719 = Constraint(expr= m.x953 - m.b1727 <= 0)
m.c720 = Constraint(expr= m.x954 - m.b1728 <= 0)
m.c721 = Constraint(expr= m.x955 - m.b1729 <= 0)
m.c722 = Constraint(expr= m.x956 - m.b1724 <= 0)
m.c723 = Constraint(expr= m.x957 - m.b1725 <= 0)
m.c724 = Constraint(expr= m.x958 - m.b1726 <= 0)
m.c725 = Constraint(expr= m.x959 - m.b1727 <= 0)
m.c726 = Constraint(expr= m.x960 - m.b1728 <= 0)
m.c727 = Constraint(expr= m.x961 - m.b1729 <= 0)
m.c728 = Constraint(expr= m.x962 - m.b1724 <= 0)
m.c729 = Constraint(expr= m.x963 - m.b1725 <= 0)
m.c730 = Constraint(expr= m.x964 - m.b1726 <= 0)
m.c731 = Constraint(expr= m.x965 - m.b1727 <= 0)
m.c732 = Constraint(expr= m.x966 - m.b1728 <= 0)
m.c733 = Constraint(expr= m.x967 - m.b1729 <= 0)
m.c734 = Constraint(expr= m.x968 - m.b1724 <= 0)
m.c735 = Constraint(expr= m.x969 - m.b1725 <= 0)
m.c736 = Constraint(expr= m.x970 - m.b1726 <= 0)
m.c737 = Constraint(expr= m.x971 - m.b1727 <= 0)
m.c738 = Constraint(expr= m.x972 - m.b1728 <= 0)
m.c739 = Constraint(expr= m.x973 - m.b1729 <= 0)
m.c740 = Constraint(expr= m.x974 - m.b1724 <= 0)
m.c741 = Constraint(expr= m.x975 - m.b1725 <= 0)
m.c742 = Constraint(expr= m.x976 - m.b1726 <= 0)
m.c743 = Constraint(expr= m.x977 - m.b1727 <= 0)
m.c744 = Constraint(expr= m.x978 - m.b1728 <= 0)
m.c745 = Constraint(expr= m.x979 - m.b1729 <= 0)
m.c746 = Constraint(expr= m.x980 - m.b1724 <= 0)
m.c747 = Constraint(expr= m.x981 - m.b1725 <= 0)
m.c748 = Constraint(expr= m.x982 - m.b1726 <= 0)
m.c749 = Constraint(expr= m.x983 - m.b1727 <= 0)
m.c750 = Constraint(expr= m.x984 - m.b1728 <= 0)
m.c751 = Constraint(expr= m.x985 - m.b1729 <= 0)
m.c752 = Constraint(expr= m.x986 - m.b1730 <= 0)
m.c753 = Constraint(expr= m.x992 - m.b1730 <= 0)
m.c754 = Constraint(expr= m.x993 - m.b1731 <= 0)
m.c755 = Constraint(expr= m.x994 - m.b1732 <= 0)
m.c756 = Constraint(expr= m.x995 - m.b1733 <= 0)
m.c757 = Constraint(expr= m.x996 - m.b1734 <= 0)
m.c758 = Constraint(expr= m.x997 - m.b1735 <= 0)
m.c759 = Constraint(expr= m.x998 - m.b1736 <= 0)
m.c760 = Constraint(expr= m.x1004 - m.b1736 <= 0)
m.c761 = Constraint(expr= m.x1005 - m.b1737 <= 0)
m.c762 = Constraint(expr= m.x1006 - m.b1738 <= 0)
m.c763 = Constraint(expr= m.x1007 - m.b1739 <= 0)
m.c764 = Constraint(expr= m.x1008 - m.b1740 <= 0)
m.c765 = Constraint(expr= m.x1009 - m.b1741 <= 0)
m.c766 = Constraint(expr= m.x1010 - m.b1736 <= 0)
m.c767 = Constraint(expr= m.x1011 - m.b1737 <= 0)
m.c768 = Constraint(expr= m.x1012 - m.b1738 <= 0)
m.c769 = Constraint(expr= m.x1013 - m.b1739 <= 0)
m.c770 = Constraint(expr= m.x1014 - m.b1740 <= 0)
m.c771 = Constraint(expr= m.x1015 - m.b1741 <= 0)
m.c772 = Constraint(expr= m.x1016 - m.b1742 <= 0)
m.c773 = Constraint(expr= m.x1017 - m.b1743 <= 0)
m.c774 = Constraint(expr= m.x1022 - m.b1742 <= 0)
m.c775 = Constraint(expr= m.x1023 - m.b1743 <= 0)
m.c776 = Constraint(expr= m.x1024 - m.b1744 <= 0)
m.c777 = Constraint(expr= m.x1025 - m.b1745 <= 0)
m.c778 = Constraint(expr= m.x1026 - m.b1746 <= 0)
m.c779 = Constraint(expr= m.x1028 - m.b1742 <= 0)
m.c780 = Constraint(expr= m.x1029 - m.b1743 <= 0)
m.c781 = Constraint(expr= m.x1030 - m.b1744 <= 0)
m.c782 = Constraint(expr= m.x1031 - m.b1745 <= 0)
m.c783 = Constraint(expr= m.x1032 - m.b1746 <= 0)
m.c784 = Constraint(expr= m.x1033 - m.b1747 <= 0)
m.c785 = Constraint(expr= m.x1034 - m.b1742 <= 0)
m.c786 = Constraint(expr= m.x1035 - m.b1743 <= 0)
m.c787 = Constraint(expr= m.x1036 - m.b1744 <= 0)
m.c788 = Constraint(expr= m.x1037 - m.b1745 <= 0)
m.c789 = Constraint(expr= m.x1038 - m.b1746 <= 0)
m.c790 = Constraint(expr= m.x1039 - m.b1747 <= 0)
m.c791 = Constraint(expr= m.x1040 - m.b1742 <= 0)
m.c792 = Constraint(expr= m.x1041 - m.b1743 <= 0)
m.c793 = Constraint(expr= m.x1042 - m.b1744 <= 0)
m.c794 = Constraint(expr= m.x1043 - m.b1745 <= 0)
m.c795 = Constraint(expr= m.x1044 - m.b1746 <= 0)
m.c796 = Constraint(expr= m.x1045 - m.b1747 <= 0)
m.c797 = Constraint(expr= m.x1046 - m.b1742 <= 0)
m.c798 = Constraint(expr= m.x1047 - m.b1743 <= 0)
m.c799 = Constraint(expr= m.x1048 - m.b1744 <= 0)
m.c800 = Constraint(expr= m.x1049 - m.b1745 <= 0)
m.c801 = Constraint(expr= m.x1050 - m.b1746 <= 0)
m.c802 = Constraint(expr= m.x1051 - m.b1747 <= 0)
m.c803 = Constraint(expr= m.x1052 - m.b1742 <= 0)
m.c804 = Constraint(expr= m.x1053 - m.b1743 <= 0)
m.c805 = Constraint(expr= m.x1054 - m.b1744 <= 0)
m.c806 = Constraint(expr= m.x1055 - m.b1745 <= 0)
m.c807 = Constraint(expr= m.x1056 - m.b1746 <= 0)
m.c808 = Constraint(expr= m.x1057 - m.b1747 <= 0)
m.c809 = Constraint(expr= m.x1058 - m.b1748 <= 0)
m.c810 = Constraint(expr= m.x1059 - m.b1749 <= 0)
m.c811 = Constraint(expr= m.x1064 - m.b1748 <= 0)
m.c812 = Constraint(expr= m.x1065 - m.b1749 <= 0)
m.c813 = Constraint(expr= m.x1066 - m.b1750 <= 0)
m.c814 = Constraint(expr= m.x1067 - m.b1751 <= 0)
m.c815 = Constraint(expr= m.x1068 - m.b1752 <= 0)
m.c816 = Constraint(expr= m.x1069 - m.b1753 <= 0)
m.c817 = Constraint(expr= m.x1070 - m.b1748 <= 0)
m.c818 = Constraint(expr= m.x1071 - m.b1749 <= 0)
m.c819 = Constraint(expr= m.x1072 - m.b1750 <= 0)
m.c820 = Constraint(expr= m.x1073 - m.b1751 <= 0)
m.c821 = Constraint(expr= m.x1074 - m.b1752 <= 0)
m.c822 = Constraint(expr= m.x1075 - m.b1753 <= 0)
m.c823 = Constraint(expr= m.x1076 - m.b1748 <= 0)
m.c824 = Constraint(expr= m.x1077 - m.b1749 <= 0)
m.c825 = Constraint(expr= m.x1078 - m.b1750 <= 0)
m.c826 = Constraint(expr= m.x1079 - m.b1751 <= 0)
m.c827 = Constraint(expr= m.x1080 - m.b1752 <= 0)
m.c828 = Constraint(expr= m.x1081 - m.b1753 <= 0)
m.c829 = Constraint(expr= m.x1082 - m.b1748 <= 0)
m.c830 = Constraint(expr= m.x1083 - m.b1749 <= 0)
m.c831 = Constraint(expr= m.x1084 - m.b1750 <= 0)
m.c832 = Constraint(expr= m.x1085 - m.b1751 <= 0)
m.c833 = Constraint(expr= m.x1086 - m.b1752 <= 0)
m.c834 = Constraint(expr= m.x1087 - m.b1753 <= 0)
m.c835 = Constraint(expr= m.x1088 - m.b1748 <= 0)
m.c836 = Constraint(expr= m.x1089 - m.b1749 <= 0)
m.c837 = Constraint(expr= m.x1090 - m.b1750 <= 0)
m.c838 = Constraint(expr= m.x1091 - m.b1751 <= 0)
m.c839 = Constraint(expr= m.x1092 - m.b1752 <= 0)
m.c840 = Constraint(expr= m.x1093 - m.b1753 <= 0)
m.c841 = Constraint(expr= m.x1094 - m.b1748 <= 0)
m.c842 = Constraint(expr= m.x1095 - m.b1749 <= 0)
m.c843 = Constraint(expr= m.x1096 - m.b1750 <= 0)
m.c844 = Constraint(expr= m.x1097 - m.b1751 <= 0)
m.c845 = Constraint(expr= m.x1098 - m.b1752 <= 0)
m.c846 = Constraint(expr= m.x1099 - m.b1753 <= 0)
m.c847 = Constraint(expr= m.x1100 - m.b1754 <= 0)
m.c848 = Constraint(expr= m.x1106 - m.b1754 <= 0)
m.c849 = Constraint(expr= m.x1107 - m.b1755 <= 0)
m.c850 = Constraint(expr= m.x1108 - m.b1756 <= 0)
m.c851 = Constraint(expr= m.x1109 - m.b1757 <= 0)
m.c852 = Constraint(expr= m.x1110 - m.b1758 <= 0)
m.c853 = Constraint(expr= m.x1111 - m.b1759 <= 0)
m.c854 = Constraint(expr= m.x1112 - m.b1760 <= 0)
m.c855 = Constraint(expr= m.x1118 - m.b1760 <= 0)
m.c856 = Constraint(expr= m.x1119 - m.b1761 <= 0)
m.c857 = Constraint(expr= m.x1120 - m.b1762 <= 0)
m.c858 = Constraint(expr= m.x1121 - m.b1763 <= 0)
m.c859 = Constraint(expr= m.x1122 - m.b1764 <= 0)
m.c860 = Constraint(expr= m.x1123 - m.b1765 <= 0)
m.c861 = Constraint(expr= m.x1124 - m.b1760 <= 0)
m.c862 = Constraint(expr= m.x1125 - m.b1761 <= 0)
m.c863 = Constraint(expr= m.x1126 - m.b1762 <= 0)
m.c864 = Constraint(expr= m.x1127 - m.b1763 <= 0)
m.c865 = Constraint(expr= m.x1128 - m.b1764 <= 0)
m.c866 = Constraint(expr= m.x1129 - m.b1765 <= 0)
m.c867 = Constraint(expr= m.x1130 - m.b1766 <= 0)
m.c868 = Constraint(expr= m.x1136 - m.b1766 <= 0)
m.c869 = Constraint(expr= m.x1137 - m.b1767 <= 0)
m.c870 = Constraint(expr= m.x1138 - m.b1768 <= 0)
m.c871 = Constraint(expr= m.x1139 - m.b1769 <= 0)
m.c872 = Constraint(expr= m.x1140 - m.b1770 <= 0)
m.c873 = Constraint(expr= m.x1141 - m.b1771 <= 0)
m.c874 = Constraint(expr= m.x1142 - m.b1766 <= 0)
m.c875 = Constraint(expr= m.x1143 - m.b1767 <= 0)
m.c876 = Constraint(expr= m.x1144 - m.b1768 <= 0)
m.c877 = Constraint(expr= m.x1145 - m.b1769 <= 0)
m.c878 = Constraint(expr= m.x1146 - m.b1770 <= 0)
m.c879 = Constraint(expr= m.x1147 - m.b1771 <= 0)
m.c880 = Constraint(expr= m.x1148 - m.b1766 <= 0)
m.c881 = Constraint(expr= m.x1149 - m.b1767 <= 0)
m.c882 = Constraint(expr= m.x1150 - m.b1768 <= 0)
m.c883 = Constraint(expr= m.x1151 - m.b1769 <= 0)
m.c884 = Constraint(expr= m.x1152 - m.b1770 <= 0)
m.c885 = Constraint(expr= m.x1153 - m.b1771 <= 0)
m.c886 = Constraint(expr= m.x1154 - m.b1772 <= 0)
m.c887 = Constraint(expr= m.x1160 - m.b1772 <= 0)
m.c888 = Constraint(expr= m.x1161 - m.b1773 <= 0)
m.c889 = Constraint(expr= m.x1162 - m.b1774 <= 0)
m.c890 = Constraint(expr= m.x1163 - m.b1775 <= 0)
m.c891 = Constraint(expr= m.x1164 - m.b1776 <= 0)
m.c892 = Constraint(expr= m.x1165 - m.b1777 <= 0)
m.c893 = Constraint(expr= m.x1166 - m.b1772 <= 0)
m.c894 = Constraint(expr= m.x1167 - m.b1773 <= 0)
m.c895 = Constraint(expr= m.x1168 - m.b1774 <= 0)
m.c896 = Constraint(expr= m.x1169 - m.b1775 <= 0)
m.c897 = Constraint(expr= m.x1170 - m.b1776 <= 0)
m.c898 = Constraint(expr= m.x1171 - m.b1777 <= 0)
m.c899 = Constraint(expr= m.x1172 - m.b1772 <= 0)
m.c900 = Constraint(expr= m.x1173 - m.b1773 <= 0)
m.c901 = Constraint(expr= m.x1174 - m.b1774 <= 0)
m.c902 = Constraint(expr= m.x1175 - m.b1775 <= 0)
m.c903 = Constraint(expr= m.x1176 - m.b1776 <= 0)
m.c904 = Constraint(expr= m.x1177 - m.b1777 <= 0)
m.c905 = Constraint(expr= m.x1178 - m.b1772 <= 0)
m.c906 = Constraint(expr= m.x1179 - m.b1773 <= 0)
m.c907 = Constraint(expr= m.x1180 - m.b1774 <= 0)
m.c908 = Constraint(expr= m.x1181 - m.b1775 <= 0)
m.c909 = Constraint(expr= m.x1182 - m.b1776 <= 0)
m.c910 = Constraint(expr= m.x1183 - m.b1777 <= 0)
m.c911 = Constraint(expr= m.x1184 - m.b1778 <= 0)
m.c912 = Constraint(expr= m.x1190 - m.b1778 <= 0)
m.c913 = Constraint(expr= m.x1191 - m.b1779 <= 0)
m.c914 = Constraint(expr= m.x1192 - m.b1780 <= 0)
m.c915 = Constraint(expr= m.x1193 - m.b1781 <= 0)
m.c916 = Constraint(expr= m.x1194 - m.b1782 <= 0)
m.c917 = Constraint(expr= m.x1195 - m.b1783 <= 0)
m.c918 = Constraint(expr= m.x1196 - m.b1778 <= 0)
m.c919 = Constraint(expr= m.x1197 - m.b1779 <= 0)
m.c920 = Constraint(expr= m.x1198 - m.b1780 <= 0)
m.c921 = Constraint(expr= m.x1199 - m.b1781 <= 0)
m.c922 = Constraint(expr= m.x1200 - m.b1782 <= 0)
m.c923 = Constraint(expr= m.x1201 - m.b1783 <= 0)
m.c924 = Constraint(expr= m.x1202 - m.b1778 <= 0)
m.c925 = Constraint(expr= m.x1203 - m.b1779 <= 0)
m.c926 = Constraint(expr= m.x1204 - m.b1780 <= 0)
m.c927 = Constraint(expr= m.x1205 - m.b1781 <= 0)
m.c928 = Constraint(expr= m.x1206 - m.b1782 <= 0)
m.c929 = Constraint(expr= m.x1207 - m.b1783 <= 0)
m.c930 = Constraint(expr= m.x1208 - m.b1778 <= 0)
m.c931 = Constraint(expr= m.x1209 - m.b1779 <= 0)
m.c932 = Constraint(expr= m.x1210 - m.b1780 <= 0)
m.c933 = Constraint(expr= m.x1211 - m.b1781 <= 0)
m.c934 = Constraint(expr= m.x1212 - m.b1782 <= 0)
m.c935 = Constraint(expr= m.x1213 - m.b1783 <= 0)
m.c936 = Constraint(expr= m.x1214 - m.b1778 <= 0)
m.c937 = Constraint(expr= m.x1215 - m.b1779 <= 0)
m.c938 = Constraint(expr= m.x1216 - m.b1780 <= 0)
m.c939 = Constraint(expr= m.x1217 - m.b1781 <= 0)
m.c940 = Constraint(expr= m.x1218 - m.b1782 <= 0)
m.c941 = Constraint(expr= m.x1219 - m.b1783 <= 0)
m.c942 = Constraint(expr= m.x1220 - m.b1784 <= 0)
m.c943 = Constraint(expr= m.x1226 - m.b1784 <= 0)
m.c944 = Constraint(expr= m.x1227 - m.b1785 <= 0)
m.c945 = Constraint(expr= m.x1228 - m.b1786 <= 0)
m.c946 = Constraint(expr= m.x1229 - m.b1787 <= 0)
m.c947 = Constraint(expr= m.x1232 - m.b1790 <= 0)
m.c948 = Constraint(expr= m.x1238 - m.b1790 <= 0)
m.c949 = Constraint(expr= m.x1239 - m.b1791 <= 0)
m.c950 = Constraint(expr= m.x1240 - m.b1792 <= 0)
m.c951 = Constraint(expr= m.x1241 - m.b1793 <= 0)
m.c952 = Constraint(expr= m.x1244 - m.b1790 <= 0)
m.c953 = Constraint(expr= m.x1245 - m.b1791 <= 0)
m.c954 = Constraint(expr= m.x1246 - m.b1792 <= 0)
m.c955 = Constraint(expr= m.x1247 - m.b1793 <= 0)
m.c956 = Constraint(expr= m.x1248 - m.b1794 <= 0)
m.c957 = Constraint(expr= m.x1249 - m.b1795 <= 0)
m.c958 = Constraint(expr= m.x1250 - m.b1790 <= 0)
m.c959 = Constraint(expr= m.x1251 - m.b1791 <= 0)
m.c960 = Constraint(expr= m.x1252 - m.b1792 <= 0)
m.c961 = Constraint(expr= m.x1253 - m.b1793 <= 0)
m.c962 = Constraint(expr= m.x1254 - m.b1794 <= 0)
m.c963 = Constraint(expr= m.x1255 - m.b1795 <= 0)
m.c964 = Constraint(expr= m.x1256 - m.b1796 <= 0)
m.c965 = Constraint(expr= m.x1257 - m.b1797 <= 0)
m.c966 = Constraint(expr= m.x1258 - m.b1798 <= 0)
m.c967 = Constraint(expr= m.x1259 - m.b1799 <= 0)
m.c968 = Constraint(expr= m.x1260 - m.b1800 <= 0)
m.c969 = Constraint(expr= m.x1261 - m.b1801 <= 0)
m.c970 = Constraint(expr= m.x1262 - m.b1796 <= 0)
m.c971 = Constraint(expr= m.x1263 - m.b1797 <= 0)
m.c972 = Constraint(expr= m.x1264 - m.b1798 <= 0)
m.c973 = Constraint(expr= m.x1265 - m.b1799 <= 0)
m.c974 = Constraint(expr= m.x1266 - m.b1800 <= 0)
m.c975 = Constraint(expr= m.x1267 - m.b1801 <= 0)
m.c976 = Constraint(expr= m.x1268 - m.b1796 <= 0)
m.c977 = Constraint(expr= m.x1269 - m.b1797 <= 0)
m.c978 = Constraint(expr= m.x1270 - m.b1798 <= 0)
m.c979 = Constraint(expr= m.x1271 - m.b1799 <= 0)
m.c980 = Constraint(expr= m.x1272 - m.b1800 <= 0)
m.c981 = Constraint(expr= m.x1273 - m.b1801 <= 0)
m.c982 = Constraint(expr= m.x1274 - m.b1802 <= 0)
m.c983 = Constraint(expr= m.x1275 - m.b1803 <= 0)
m.c984 = Constraint(expr= m.x1276 - m.b1804 <= 0)
m.c985 = Constraint(expr= m.x1277 - m.b1805 <= 0)
m.c986 = Constraint(expr= m.x1278 - m.b1806 <= 0)
m.c987 = Constraint(expr= m.x1279 - m.b1807 <= 0)
m.c988 = Constraint(expr= m.x1280 - m.b1808 <= 0)
m.c989 = Constraint(expr= m.x1281 - m.b1809 <= 0)
m.c990 = Constraint(expr= m.x1282 - m.b1810 <= 0)
m.c991 = Constraint(expr= m.x1283 - m.b1811 <= 0)
m.c992 = Constraint(expr= m.x1284 - m.b1812 <= 0)
m.c993 = Constraint(expr= m.x1285 - m.b1813 <= 0)
m.c994 = Constraint(expr= m.x1286 - m.b1808 <= 0)
m.c995 = Constraint(expr= m.x1287 - m.b1809 <= 0)
m.c996 = Constraint(expr= m.x1288 - m.b1810 <= 0)
m.c997 = Constraint(expr= m.x1289 - m.b1811 <= 0)
m.c998 = Constraint(expr= m.x1290 - m.b1812 <= 0)
m.c999 = Constraint(expr= m.x1291 - m.b1813 <= 0)
m.c1000 = Constraint(expr= m.x1292 - m.b1814 <= 0)
m.c1001 = Constraint(expr= m.x1293 - m.b1815 <= 0)
m.c1002 = Constraint(expr= m.x1294 - m.b1816 <= 0)
m.c1003 = Constraint(expr= m.x1295 - m.b1817 <= 0)
m.c1004 = Constraint(expr= m.x1296 - m.b1818 <= 0)
m.c1005 = Constraint(expr= m.x1298 - m.b1820 <= 0)
m.c1006 = Constraint(expr= m.x1299 - m.b1821 <= 0)
m.c1007 = Constraint(expr= m.x1300 - m.b1822 <= 0)
m.c1008 = Constraint(expr= m.x1301 - m.b1823 <= 0)
m.c1009 = Constraint(expr= m.x1302 - m.b1824 <= 0)
m.c1010 = Constraint(expr= m.x1304 - m.b1820 <= 0)
m.c1011 = Constraint(expr= m.x1305 - m.b1821 <= 0)
m.c1012 = Constraint(expr= m.x1306 - m.b1822 <= 0)
m.c1013 = Constraint(expr= m.x1307 - m.b1823 <= 0)
m.c1014 = Constraint(expr= m.x1308 - m.b1824 <= 0)
m.c1015 = Constraint(expr= m.x1309 - m.b1825 <= 0)
m.c1016 = Constraint(expr= m.x1310 - m.b1820 <= 0)
m.c1017 = Constraint(expr= m.x1311 - m.b1821 <= 0)
m.c1018 = Constraint(expr= m.x1312 - m.b1822 <= 0)
m.c1019 = Constraint(expr= m.x1313 - m.b1823 <= 0)
m.c1020 = Constraint(expr= m.x1314 - m.b1824 <= 0)
m.c1021 = Constraint(expr= m.x1315 - m.b1825 <= 0)
m.c1022 = Constraint(expr= m.x1316 - m.b1826 <= 0)
m.c1023 = Constraint(expr= m.x1322 - m.b1826 <= 0)
m.c1024 = Constraint(expr= m.x1323 - m.b1827 <= 0)
m.c1025 = Constraint(expr= m.x1324 - m.b1828 <= 0)
m.c1026 = Constraint(expr= m.x1325 - m.b1829 <= 0)
m.c1027 = Constraint(expr= m.x1328 - m.b1826 <= 0)
m.c1028 = Constraint(expr= m.x1329 - m.b1827 <= 0)
m.c1029 = Constraint(expr= m.x1330 - m.b1828 <= 0)
m.c1030 = Constraint(expr= m.x1331 - m.b1829 <= 0)
m.c1031 = Constraint(expr= m.x1332 - m.b1830 <= 0)
m.c1032 = Constraint(expr= m.x1333 - m.b1831 <= 0)
m.c1033 = Constraint(expr= m.x1334 - m.b1832 <= 0)
m.c1034 = Constraint(expr= m.x1340 - m.b1832 <= 0)
m.c1035 = Constraint(expr= m.x1341 - m.b1833 <= 0)
m.c1036 = Constraint(expr= m.x1342 - m.b1834 <= 0)
m.c1037 = Constraint(expr= m.x1343 - m.b1835 <= 0)
m.c1038 = Constraint(expr= m.x1346 - m.b1832 <= 0)
m.c1039 = Constraint(expr= m.x1347 - m.b1833 <= 0)
m.c1040 = Constraint(expr= m.x1348 - m.b1834 <= 0)
m.c1041 = Constraint(expr= m.x1349 - m.b1835 <= 0)
m.c1042 = Constraint(expr= m.x1350 - m.b1836 <= 0)
m.c1043 = Constraint(expr= m.x1351 - m.b1837 <= 0)
m.c1044 = Constraint(expr= m.x1352 - m.b1838 <= 0)
m.c1045 = Constraint(expr= m.x1358 - m.b1844 <= 0)
m.c1046 = Constraint(expr= m.x1359 - m.b1845 <= 0)
m.c1047 = Constraint(expr= m.x1360 - m.b1846 <= 0)
m.c1048 = Constraint(expr= m.x1361 - m.b1847 <= 0)
m.c1049 = Constraint(expr= m.x1362 - m.b1848 <= 0)
m.c1050 = Constraint(expr= m.x1363 - m.b1849 <= 0)
m.c1051 = Constraint(expr= m.x1364 - m.b1850 <= 0)
m.c1052 = Constraint(expr= m.x1370 - m.b1850 <= 0)
m.c1053 = Constraint(expr= m.x1371 - m.b1851 <= 0)
m.c1054 = Constraint(expr= m.x1372 - m.b1852 <= 0)
m.c1055 = Constraint(expr= m.x1373 - m.b1853 <= 0)
m.c1056 = Constraint(expr= m.x1376 - m.b1856 <= 0)
m.c1057 = Constraint(expr= m.x1382 - m.b1856 <= 0)
m.c1058 = Constraint(expr= m.x1383 - m.b1857 <= 0)
m.c1059 = Constraint(expr= m.x1384 - m.b1858 <= 0)
m.c1060 = Constraint(expr= m.x1385 - m.b1859 <= 0)
m.c1061 = Constraint(expr= m.x1386 - m.b1860 <= 0)
m.c1062 = Constraint(expr= m.x1387 - m.b1861 <= 0)
m.c1063 = Constraint(expr= m.x1388 - m.b1862 <= 0)
m.c1064 = Constraint(expr= m.x1389 - m.b1863 <= 0)
m.c1065 = Constraint(expr= m.x1390 - m.b1864 <= 0)
m.c1066 = Constraint(expr= m.x1391 - m.b1865 <= 0)
m.c1067 = Constraint(expr= m.x1392 - m.b1866 <= 0)
m.c1068 = Constraint(expr= m.x1393 - m.b1867 <= 0)
m.c1069 = Constraint(expr= m.x1394 - m.b1868 <= 0)
m.c1070 = Constraint(expr= m.x1395 - m.b1869 <= 0)
m.c1071 = Constraint(expr= m.x1396 - m.b1870 <= 0)
m.c1072 = Constraint(expr= m.x1397 - m.b1871 <= 0)
m.c1073 = Constraint(expr= m.x1398 - m.b1872 <= 0)
m.c1074 = Constraint(expr= m.x1399 - m.b1873 <= 0)
m.c1075 = Constraint(expr= m.x1400 - m.b1868 <= 0)
m.c1076 = Constraint(expr= m.x1401 - m.b1869 <= 0)
m.c1077 = Constraint(expr= m.x1402 - m.b1870 <= 0)
m.c1078 = Constraint(expr= m.x1403 - m.b1871 <= 0)
m.c1079 = Constraint(expr= m.x1404 - m.b1872 <= 0)
m.c1080 = Constraint(expr= m.x1405 - m.b1873 <= 0)
m.c1081 = Constraint(expr= m.x1406 - m.b1874 <= 0)
m.c1082 = Constraint(expr= m.x1407 - m.b1875 <= 0)
m.c1083 = Constraint(expr= m.x1408 - m.b1876 <= 0)
m.c1084 = Constraint(expr= m.x1409 - m.b1877 <= 0)
m.c1085 = Constraint(expr= m.x1410 - m.b1878 <= 0)
m.c1086 = Constraint(expr= m.x1411 - m.b1879 <= 0)
m.c1087 = Constraint(expr= m.x1412 - m.b1874 <= 0)
m.c1088 = Constraint(expr= m.x1413 - m.b1875 <= 0)
m.c1089 = Constraint(expr= m.x1414 - m.b1876 <= 0)
m.c1090 = Constraint(expr= m.x1415 - m.b1877 <= 0)
m.c1091 = Constraint(expr= m.x1416 - m.b1878 <= 0)
m.c1092 = Constraint(expr= m.x1417 - m.b1879 <= 0)
m.c1093 = Constraint(expr= m.x1418 - m.b1880 <= 0)
m.c1094 = Constraint(expr= m.x1419 - m.b1881 <= 0)
m.c1095 = Constraint(expr= m.x1420 - m.b1882 <= 0)
m.c1096 = Constraint(expr= m.x1424 - m.b1880 <= 0)
m.c1097 = Constraint(expr= m.x1425 - m.b1881 <= 0)
m.c1098 = Constraint(expr= m.x1426 - m.b1882 <= 0)
m.c1099 = Constraint(expr= m.x1427 - m.b1883 <= 0)
m.c1100 = Constraint(expr= m.x1428 - m.b1884 <= 0)
m.c1101 = Constraint(expr= m.x1429 - m.b1885 <= 0)
m.c1102 = Constraint(expr= m.x1430 - m.b1886 <= 0)
m.c1103 = Constraint(expr= m.x1431 - m.b1887 <= 0)
m.c1104 = Constraint(expr= m.x1436 - m.b1892 <= 0)
m.c1105 = Constraint(expr= m.x1437 - m.b1893 <= 0)
m.c1106 = Constraint(expr= m.x1442 - m.b1892 <= 0)
m.c1107 = Constraint(expr= m.x1443 - m.b1893 <= 0)
m.c1108 = Constraint(expr= m.x1444 - m.b1894 <= 0)
m.c1109 = Constraint(expr= m.x1445 - m.b1895 <= 0)
m.c1110 = Constraint(expr= m.x1446 - m.b1896 <= 0)
m.c1111 = Constraint(expr= m.x1447 - m.b1897 <= 0)
m.c1112 = Constraint(expr= m.x1448 - m.b1898 <= 0)
m.c1113 = Constraint(expr= m.x1449 - m.b1899 <= 0)
m.c1114 = Constraint(expr= m.x1450 - m.b1900 <= 0)
m.c1115 = Constraint(expr= m.x1451 - m.b1901 <= 0)
m.c1116 = Constraint(expr= m.x1452 - m.b1902 <= 0)
m.c1117 = Constraint(expr= m.x1453 - m.b1903 <= 0)
m.c1118 = Constraint(expr= m.x1454 - m.b1904 <= 0)
m.c1119 = Constraint(expr= m.x1455 - m.b1905 <= 0)
m.c1120 = Constraint(expr= m.x1456 - m.b1906 <= 0)
m.c1121 = Constraint(expr= m.x1457 - m.b1907 <= 0)
m.c1122 = Constraint(expr= m.x1458 - m.b1908 <= 0)
m.c1123 = Constraint(expr= m.x1459 - m.b1909 <= 0)
m.c1124 = Constraint(expr= m.x1460 - m.b1910 <= 0)
m.c1125 = Constraint(expr= m.x1461 - m.b1911 <= 0)
m.c1126 = Constraint(expr= m.x1462 - m.b1912 <= 0)
m.c1127 = Constraint(expr= m.x1463 - m.b1913 <= 0)
m.c1128 = Constraint(expr= m.x1464 - m.b1914 <= 0)
m.c1129 = Constraint(expr= m.x1465 - m.b1915 <= 0)
m.c1130 = Constraint(expr= m.x1466 - m.b1916 <= 0)
m.c1131 = Constraint(expr= m.x1467 - m.b1917 <= 0)
m.c1132 = Constraint(expr= m.x1468 - m.b1918 <= 0)
m.c1133 = Constraint(expr= m.x1469 - m.b1919 <= 0)
m.c1134 = Constraint(expr= m.x1470 - m.b1920 <= 0)
m.c1135 = Constraint(expr= m.x1471 - m.b1921 <= 0)
m.c1136 = Constraint(expr= m.x1472 - m.b1922 <= 0)
m.c1137 = Constraint(expr= m.x1473 - m.b1923 <= 0)
m.c1138 = Constraint(expr= m.x1474 - m.b1924 <= 0)
m.c1139 = Constraint(expr= m.x1475 - m.b1925 <= 0)
m.c1140 = Constraint(expr= m.x1476 - m.b1926 <= 0)
m.c1141 = Constraint(expr= m.x1477 - m.b1927 <= 0)
m.c1142 = Constraint(expr= m.x1478 - m.b1928 <= 0)
m.c1143 = Constraint(expr= m.x1479 - m.b1929 <= 0)
m.c1144 = Constraint(expr= m.x1480 - m.b1930 <= 0)
m.c1145 = Constraint(expr= m.x1481 - m.b1931 <= 0)
m.c1146 = Constraint(expr= m.x1482 - m.b1932 <= 0)
m.c1147 = Constraint(expr= m.x1483 - m.b1933 <= 0)
m.c1148 = Constraint(expr= m.x1484 - m.b1934 <= 0)
m.c1149 = Constraint(expr= m.x1485 - m.b1935 <= 0)
m.c1150 = Constraint(expr= m.x1486 - m.b1936 <= 0)
m.c1151 = Constraint(expr= m.x1487 - m.b1937 <= 0)
m.c1152 = Constraint(expr= m.x1488 - m.b1938 <= 0)
m.c1153 = Constraint(expr= m.x1489 - m.b1939 <= 0)
m.c1154 = Constraint(expr= m.x1490 - m.b1946 <= 0)
m.c1155 = Constraint(expr= m.x1496 - m.b1952 <= 0)
m.c1156 = Constraint(expr= m.x1502 - m.b1958 <= 0)
m.c1157 = Constraint(expr= m.x1508 - m.b1964 <= 0)
m.c1158 = Constraint(expr= m.x1514 - m.b1970 <= 0)
m.c1159 = Constraint(expr= m.x1515 - m.b1971 <= 0)
m.c1160 = Constraint(expr= m.x1516 - m.b1972 <= 0)
m.c1161 = Constraint(expr= m.x1517 - m.b1973 <= 0)
m.c1162 = Constraint(expr= m.x1518 - m.b1974 <= 0)
m.c1163 = Constraint(expr= m.x1520 - m.b1976 <= 0)
m.c1164 = Constraint(expr= m.x1521 - m.b1977 <= 0)
m.c1165 = Constraint(expr= m.x1522 - m.b1978 <= 0)
m.c1166 = Constraint(expr= m.x1523 - m.b1979 <= 0)
m.c1167 = Constraint(expr= m.x1524 - m.b1980 <= 0)
m.c1168 = Constraint(expr= m.x1525 - m.b1981 <= 0)
m.c1169 = Constraint(expr= m.x1526 - m.b1988 <= 0)
m.c1170 = Constraint(expr= m.x1527 - m.b1989 <= 0)
m.c1171 = Constraint(expr= m.x1528 - m.b1990 <= 0)
m.c1172 = Constraint(expr= m.x1529 - m.b1991 <= 0)
m.c1173 = Constraint(expr= m.x1530 - m.b1992 <= 0)
m.c1174 = Constraint(expr= m.x1531 - m.b1993 <= 0)
m.c1175 = Constraint(expr= m.x1532 - m.b1994 <= 0)
m.c1176 = Constraint(expr= m.x1533 - m.b1995 <= 0)
m.c1177 = Constraint(expr= m.x1534 - m.b1996 <= 0)
m.c1178 = Constraint(expr= m.x1535 - m.b1997 <= 0)
m.c1179 = Constraint(expr= m.x1536 - m.b1998 <= 0)
m.c1180 = Constraint(expr= m.x1537 - m.b1999 <= 0)
m.c1181 = Constraint(expr= m.x14 - m.b1640 <= 0)
m.c1182 = Constraint(expr= m.x20 - m.b1802 <= 0)
m.c1183 = Constraint(expr= m.x26 - m.b1808 <= 0)
m.c1184 = Constraint(expr= m.x32 - m.b1940 <= 0)
m.c1185 = Constraint(expr= m.x38 - m.b1538 <= 0)
m.c1186 = Constraint(expr= m.x44 - m.b1556 <= 0)
m.c1187 = Constraint(expr= m.x45 - m.b1557 <= 0)
m.c1188 = Constraint(expr= m.x50 - m.b1562 <= 0)
m.c1189 = Constraint(expr= m.x51 - m.b1563 <= 0)
m.c1190 = Constraint(expr= m.x56 - m.b1862 <= 0)
m.c1191 = Constraint(expr= m.x57 - m.b1863 <= 0)
m.c1192 = Constraint(expr= m.x62 - m.b1538 <= 0)
m.c1193 = Constraint(expr= m.x68 - m.b1544 <= 0)
m.c1194 = Constraint(expr= m.x69 - m.b1545 <= 0)
m.c1195 = Constraint(expr= m.x74 - m.b1562 <= 0)
m.c1196 = Constraint(expr= m.x75 - m.b1563 <= 0)
m.c1197 = Constraint(expr= m.x76 - m.b1564 <= 0)
m.c1198 = Constraint(expr= m.x80 - m.b1610 <= 0)
m.c1199 = Constraint(expr= m.x81 - m.b1611 <= 0)
m.c1200 = Constraint(expr= m.x82 - m.b1612 <= 0)
m.c1201 = Constraint(expr= m.x86 - m.b1616 <= 0)
m.c1202 = Constraint(expr= m.x87 - m.b1617 <= 0)
m.c1203 = Constraint(expr= m.x88 - m.b1618 <= 0)
m.c1204 = Constraint(expr= m.x92 - m.b1670 <= 0)
m.c1205 = Constraint(expr= m.x93 - m.b1671 <= 0)
m.c1206 = Constraint(expr= m.x94 - m.b1672 <= 0)
m.c1207 = Constraint(expr= m.x98 - m.b1730 <= 0)
m.c1208 = Constraint(expr= m.x99 - m.b1731 <= 0)
m.c1209 = Constraint(expr= m.x100 - m.b1732 <= 0)
m.c1210 = Constraint(expr= m.x104 - m.b1736 <= 0)
m.c1211 = Constraint(expr= m.x105 - m.b1737 <= 0)
m.c1212 = Constraint(expr= m.x106 - m.b1738 <= 0)
m.c1213 = Constraint(expr= m.x110 - m.b1796 <= 0)
m.c1214 = Constraint(expr= m.x111 - m.b1797 <= 0)
m.c1215 = Constraint(expr= m.x112 - m.b1798 <= 0)
m.c1216 = Constraint(expr= m.x116 - m.b1814 <= 0)
m.c1217 = Constraint(expr= m.x117 - m.b1815 <= 0)
m.c1218 = Constraint(expr= m.x118 - m.b1816 <= 0)
m.c1219 = Constraint(expr= m.x122 - m.b1538 <= 0)
m.c1220 = Constraint(expr= m.x128 - m.b1562 <= 0)
m.c1221 = Constraint(expr= m.x129 - m.b1563 <= 0)
m.c1222 = Constraint(expr= m.x130 - m.b1564 <= 0)
m.c1223 = Constraint(expr= m.x131 - m.b1565 <= 0)
m.c1224 = Constraint(expr= m.x134 - m.b1568 <= 0)
m.c1225 = Constraint(expr= m.x135 - m.b1569 <= 0)
m.c1226 = Constraint(expr= m.x136 - m.b1570 <= 0)
m.c1227 = Constraint(expr= m.x137 - m.b1571 <= 0)
m.c1228 = Constraint(expr= m.x140 - m.b1604 <= 0)
m.c1229 = Constraint(expr= m.x141 - m.b1605 <= 0)
m.c1230 = Constraint(expr= m.x142 - m.b1606 <= 0)
m.c1231 = Constraint(expr= m.x143 - m.b1607 <= 0)
m.c1232 = Constraint(expr= m.x146 - m.b1610 <= 0)
m.c1233 = Constraint(expr= m.x147 - m.b1611 <= 0)
m.c1234 = Constraint(expr= m.x148 - m.b1612 <= 0)
m.c1235 = Constraint(expr= m.x149 - m.b1613 <= 0)
m.c1236 = Constraint(expr= m.x152 - m.b1538 <= 0)
m.c1237 = Constraint(expr= m.x158 - m.b1568 <= 0)
m.c1238 = Constraint(expr= m.x159 - m.b1569 <= 0)
m.c1239 = Constraint(expr= m.x160 - m.b1570 <= 0)
m.c1240 = Constraint(expr= m.x161 - m.b1571 <= 0)
m.c1241 = Constraint(expr= m.x162 - m.b1572 <= 0)
m.c1242 = Constraint(expr= m.x164 - m.b1604 <= 0)
m.c1243 = Constraint(expr= m.x165 - m.b1605 <= 0)
m.c1244 = Constraint(expr= m.x166 - m.b1606 <= 0)
m.c1245 = Constraint(expr= m.x167 - m.b1607 <= 0)
m.c1246 = Constraint(expr= m.x168 - m.b1608 <= 0)
m.c1247 = Constraint(expr= m.x170 - m.b1538 <= 0)
m.c1248 = Constraint(expr= m.x176 - m.b1670 <= 0)
m.c1249 = Constraint(expr= m.x177 - m.b1671 <= 0)
m.c1250 = Constraint(expr= m.x178 - m.b1672 <= 0)
m.c1251 = Constraint(expr= m.x179 - m.b1673 <= 0)
m.c1252 = Constraint(expr= m.x180 - m.b1674 <= 0)
m.c1253 = Constraint(expr= m.x181 - m.b1675 <= 0)
m.c1254 = Constraint(expr= m.x182 - m.b1694 <= 0)
m.c1255 = Constraint(expr= m.x183 - m.b1695 <= 0)
m.c1256 = Constraint(expr= m.x184 - m.b1696 <= 0)
m.c1257 = Constraint(expr= m.x185 - m.b1697 <= 0)
m.c1258 = Constraint(expr= m.x186 - m.b1698 <= 0)
m.c1259 = Constraint(expr= m.x187 - m.b1699 <= 0)
m.c1260 = Constraint(expr= m.x188 - m.b1700 <= 0)
m.c1261 = Constraint(expr= m.x189 - m.b1701 <= 0)
m.c1262 = Constraint(expr= m.x190 - m.b1702 <= 0)
m.c1263 = Constraint(expr= m.x191 - m.b1703 <= 0)
m.c1264 = Constraint(expr= m.x192 - m.b1704 <= 0)
m.c1265 = Constraint(expr= m.x193 - m.b1705 <= 0)
m.c1266 = Constraint(expr= m.x194 - m.b1706 <= 0)
m.c1267 = Constraint(expr= m.x195 - m.b1707 <= 0)
m.c1268 = Constraint(expr= m.x196 - m.b1708 <= 0)
m.c1269 = Constraint(expr= m.x197 - m.b1709 <= 0)
m.c1270 = Constraint(expr= m.x198 - m.b1710 <= 0)
m.c1271 = Constraint(expr= m.x199 - m.b1711 <= 0)
m.c1272 = Constraint(expr= m.x200 - m.b1712 <= 0)
m.c1273 = Constraint(expr= m.x201 - m.b1713 <= 0)
m.c1274 = Constraint(expr= m.x202 - m.b1714 <= 0)
m.c1275 = Constraint(expr= m.x203 - m.b1715 <= 0)
m.c1276 = Constraint(expr= m.x204 - m.b1716 <= 0)
m.c1277 = Constraint(expr= m.x205 - m.b1717 <= 0)
m.c1278 = Constraint(expr= m.x206 - m.b1718 <= 0)
m.c1279 = Constraint(expr= m.x207 - m.b1719 <= 0)
m.c1280 = Constraint(expr= m.x208 - m.b1720 <= 0)
m.c1281 = Constraint(expr= m.x209 - m.b1721 <= 0)
m.c1282 = Constraint(expr= m.x210 - m.b1722 <= 0)
m.c1283 = Constraint(expr= m.x211 - m.b1723 <= 0)
m.c1284 = Constraint(expr= m.x212 - m.b1724 <= 0)
m.c1285 = Constraint(expr= m.x213 - m.b1725 <= 0)
m.c1286 = Constraint(expr= m.x214 - m.b1726 <= 0)
m.c1287 = Constraint(expr= m.x215 - m.b1727 <= 0)
m.c1288 = Constraint(expr= m.x216 - m.b1728 <= 0)
m.c1289 = Constraint(expr= m.x217 - m.b1729 <= 0)
m.c1290 = Constraint(expr= m.x218 - m.b1838 <= 0)
m.c1291 = Constraint(expr= m.x219 - m.b1839 <= 0)
m.c1292 = Constraint(expr= m.x220 - m.b1840 <= 0)
m.c1293 = Constraint(expr= m.x221 - m.b1841 <= 0)
m.c1294 = Constraint(expr= m.x222 - m.b1842 <= 0)
m.c1295 = Constraint(expr= m.x223 - m.b1843 <= 0)
m.c1296 = Constraint(expr= m.x224 - m.b1538 <= 0)
m.c1297 = Constraint(expr= m.x230 - m.b1544 <= 0)
m.c1298 = Constraint(expr= m.x231 - m.b1545 <= 0)
m.c1299 = Constraint(expr= m.x236 - m.b1550 <= 0)
m.c1300 = Constraint(expr= m.x237 - m.b1551 <= 0)
m.c1301 = Constraint(expr= m.x238 - m.b1552 <= 0)
m.c1302 = Constraint(expr= m.x242 - m.b1556 <= 0)
m.c1303 = Constraint(expr= m.x243 - m.b1557 <= 0)
m.c1304 = Constraint(expr= m.x244 - m.b1558 <= 0)
m.c1305 = Constraint(expr= m.x245 - m.b1559 <= 0)
m.c1306 = Constraint(expr= m.x248 - m.b1622 <= 0)
m.c1307 = Constraint(expr= m.x249 - m.b1623 <= 0)
m.c1308 = Constraint(expr= m.x250 - m.b1624 <= 0)
m.c1309 = Constraint(expr= m.x251 - m.b1625 <= 0)
m.c1310 = Constraint(expr= m.x252 - m.b1626 <= 0)
m.c1311 = Constraint(expr= m.x253 - m.b1627 <= 0)
m.c1312 = Constraint(expr= m.x254 - m.b1544 <= 0)
m.c1313 = Constraint(expr= m.x255 - m.b1545 <= 0)
m.c1314 = Constraint(expr= m.x260 - m.b1550 <= 0)
m.c1315 = Constraint(expr= m.x261 - m.b1551 <= 0)
m.c1316 = Constraint(expr= m.x262 - m.b1552 <= 0)
m.c1317 = Constraint(expr= m.x266 - m.b1574 <= 0)
m.c1318 = Constraint(expr= m.x267 - m.b1575 <= 0)
m.c1319 = Constraint(expr= m.x268 - m.b1576 <= 0)
m.c1320 = Constraint(expr= m.x269 - m.b1577 <= 0)
m.c1321 = Constraint(expr= m.x270 - m.b1578 <= 0)
m.c1322 = Constraint(expr= m.x271 - m.b1579 <= 0)
m.c1323 = Constraint(expr= m.x272 - m.b1616 <= 0)
m.c1324 = Constraint(expr= m.x273 - m.b1617 <= 0)
m.c1325 = Constraint(expr= m.x274 - m.b1618 <= 0)
m.c1326 = Constraint(expr= m.x275 - m.b1619 <= 0)
m.c1327 = Constraint(expr= m.x276 - m.b1620 <= 0)
m.c1328 = Constraint(expr= m.x277 - m.b1621 <= 0)
m.c1329 = Constraint(expr= m.x278 - m.b1622 <= 0)
m.c1330 = Constraint(expr= m.x279 - m.b1623 <= 0)
m.c1331 = Constraint(expr= m.x280 - m.b1624 <= 0)
m.c1332 = Constraint(expr= m.x281 - m.b1625 <= 0)
m.c1333 = Constraint(expr= m.x282 - m.b1626 <= 0)
m.c1334 = Constraint(expr= m.x283 - m.b1627 <= 0)
m.c1335 = Constraint(expr= m.x284 - m.b1628 <= 0)
m.c1336 = Constraint(expr= m.x285 - m.b1629 <= 0)
m.c1337 = Constraint(expr= m.x286 - m.b1630 <= 0)
m.c1338 = Constraint(expr= m.x287 - m.b1631 <= 0)
m.c1339 = Constraint(expr= m.x288 - m.b1632 <= 0)
m.c1340 = Constraint(expr= m.x289 - m.b1633 <= 0)
m.c1341 = Constraint(expr= m.x290 - m.b1634 <= 0)
m.c1342 = Constraint(expr= m.x291 - m.b1635 <= 0)
m.c1343 = Constraint(expr= m.x292 - m.b1636 <= 0)
m.c1344 = Constraint(expr= m.x293 - m.b1637 <= 0)
m.c1345 = Constraint(expr= m.x294 - m.b1638 <= 0)
m.c1346 = Constraint(expr= m.x295 - m.b1639 <= 0)
m.c1347 = Constraint(expr= m.x296 - m.b1676 <= 0)
m.c1348 = Constraint(expr= m.x297 - m.b1677 <= 0)
m.c1349 = Constraint(expr= m.x298 - m.b1678 <= 0)
m.c1350 = Constraint(expr= m.x299 - m.b1679 <= 0)
m.c1351 = Constraint(expr= m.x300 - m.b1680 <= 0)
m.c1352 = Constraint(expr= m.x301 - m.b1681 <= 0)
m.c1353 = Constraint(expr= m.x302 - m.b1538 <= 0)
m.c1354 = Constraint(expr= m.x308 - m.b1544 <= 0)
m.c1355 = Constraint(expr= m.x309 - m.b1545 <= 0)
m.c1356 = Constraint(expr= m.x314 - m.b1550 <= 0)
m.c1357 = Constraint(expr= m.x315 - m.b1551 <= 0)
m.c1358 = Constraint(expr= m.x316 - m.b1552 <= 0)
m.c1359 = Constraint(expr= m.x320 - m.b1574 <= 0)
m.c1360 = Constraint(expr= m.x321 - m.b1575 <= 0)
m.c1361 = Constraint(expr= m.x322 - m.b1576 <= 0)
m.c1362 = Constraint(expr= m.x323 - m.b1577 <= 0)
m.c1363 = Constraint(expr= m.x324 - m.b1578 <= 0)
m.c1364 = Constraint(expr= m.x325 - m.b1579 <= 0)
m.c1365 = Constraint(expr= m.x326 - m.b1580 <= 0)
m.c1366 = Constraint(expr= m.x327 - m.b1581 <= 0)
m.c1367 = Constraint(expr= m.x328 - m.b1582 <= 0)
m.c1368 = Constraint(expr= m.x329 - m.b1583 <= 0)
m.c1369 = Constraint(expr= m.x330 - m.b1584 <= 0)
m.c1370 = Constraint(expr= m.x331 - m.b1585 <= 0)
m.c1371 = Constraint(expr= m.x332 - m.b1592 <= 0)
m.c1372 = Constraint(expr= m.x333 - m.b1593 <= 0)
m.c1373 = Constraint(expr= m.x334 - m.b1594 <= 0)
m.c1374 = Constraint(expr= m.x335 - m.b1595 <= 0)
m.c1375 = Constraint(expr= m.x336 - m.b1596 <= 0)
m.c1376 = Constraint(expr= m.x337 - m.b1597 <= 0)
m.c1377 = Constraint(expr= m.x338 - m.b1622 <= 0)
m.c1378 = Constraint(expr= m.x339 - m.b1623 <= 0)
m.c1379 = Constraint(expr= m.x340 - m.b1624 <= 0)
m.c1380 = Constraint(expr= m.x341 - m.b1625 <= 0)
m.c1381 = Constraint(expr= m.x342 - m.b1626 <= 0)
m.c1382 = Constraint(expr= m.x343 - m.b1627 <= 0)
m.c1383 = Constraint(expr= m.x344 - m.b1628 <= 0)
m.c1384 = Constraint(expr= m.x345 - m.b1629 <= 0)
m.c1385 = Constraint(expr= m.x346 - m.b1630 <= 0)
m.c1386 = Constraint(expr= m.x347 - m.b1631 <= 0)
m.c1387 = Constraint(expr= m.x348 - m.b1632 <= 0)
m.c1388 = Constraint(expr= m.x349 - m.b1633 <= 0)
m.c1389 = Constraint(expr= m.x350 - m.b1634 <= 0)
m.c1390 = Constraint(expr= m.x351 - m.b1635 <= 0)
m.c1391 = Constraint(expr= m.x352 - m.b1636 <= 0)
m.c1392 = Constraint(expr= m.x353 - m.b1637 <= 0)
m.c1393 = Constraint(expr= m.x354 - m.b1638 <= 0)
m.c1394 = Constraint(expr= m.x355 - m.b1639 <= 0)
m.c1395 = Constraint(expr= m.x356 - m.b1676 <= 0)
m.c1396 = Constraint(expr= m.x357 - m.b1677 <= 0)
m.c1397 = Constraint(expr= m.x358 - m.b1678 <= 0)
m.c1398 = Constraint(expr= m.x359 - m.b1679 <= 0)
m.c1399 = Constraint(expr= m.x360 - m.b1680 <= 0)
m.c1400 = Constraint(expr= m.x361 - m.b1681 <= 0)
m.c1401 = Constraint(expr= m.x362 - m.b1544 <= 0)
m.c1402 = Constraint(expr= m.x363 - m.b1545 <= 0)
m.c1403 = Constraint(expr= m.x368 - m.b1550 <= 0)
m.c1404 = Constraint(expr= m.x369 - m.b1551 <= 0)
m.c1405 = Constraint(expr= m.x370 - m.b1552 <= 0)
m.c1406 = Constraint(expr= m.x374 - m.b1574 <= 0)
m.c1407 = Constraint(expr= m.x375 - m.b1575 <= 0)
m.c1408 = Constraint(expr= m.x376 - m.b1576 <= 0)
m.c1409 = Constraint(expr= m.x377 - m.b1577 <= 0)
m.c1410 = Constraint(expr= m.x378 - m.b1578 <= 0)
m.c1411 = Constraint(expr= m.x379 - m.b1579 <= 0)
m.c1412 = Constraint(expr= m.x380 - m.b1580 <= 0)
m.c1413 = Constraint(expr= m.x381 - m.b1581 <= 0)
m.c1414 = Constraint(expr= m.x382 - m.b1582 <= 0)
m.c1415 = Constraint(expr= m.x383 - m.b1583 <= 0)
m.c1416 = Constraint(expr= m.x384 - m.b1584 <= 0)
m.c1417 = Constraint(expr= m.x385 - m.b1585 <= 0)
m.c1418 = Constraint(expr= m.x386 - m.b1622 <= 0)
m.c1419 = Constraint(expr= m.x387 - m.b1623 <= 0)
m.c1420 = Constraint(expr= m.x388 - m.b1624 <= 0)
m.c1421 = Constraint(expr= m.x389 - m.b1625 <= 0)
m.c1422 = Constraint(expr= m.x390 - m.b1626 <= 0)
m.c1423 = Constraint(expr= m.x391 - m.b1627 <= 0)
m.c1424 = Constraint(expr= m.x392 - m.b1628 <= 0)
m.c1425 = Constraint(expr= m.x393 - m.b1629 <= 0)
m.c1426 = Constraint(expr= m.x394 - m.b1630 <= 0)
m.c1427 = Constraint(expr= m.x395 - m.b1631 <= 0)
m.c1428 = Constraint(expr= m.x396 - m.b1632 <= 0)
m.c1429 = Constraint(expr= m.x397 - m.b1633 <= 0)
m.c1430 = Constraint(expr= m.x398 - m.b1634 <= 0)
m.c1431 = Constraint(expr= m.x399 - m.b1635 <= 0)
m.c1432 = Constraint(expr= m.x400 - m.b1636 <= 0)
m.c1433 = Constraint(expr= m.x401 - m.b1637 <= 0)
m.c1434 = Constraint(expr= m.x402 - m.b1638 <= 0)
m.c1435 = Constraint(expr= m.x403 - m.b1639 <= 0)
m.c1436 = Constraint(expr= m.x404 - m.b1676 <= 0)
m.c1437 = Constraint(expr= m.x405 - m.b1677 <= 0)
m.c1438 = Constraint(expr= m.x406 - m.b1678 <= 0)
m.c1439 = Constraint(expr= m.x407 - m.b1679 <= 0)
m.c1440 = Constraint(expr= m.x408 - m.b1680 <= 0)
m.c1441 = Constraint(expr= m.x409 - m.b1681 <= 0)
m.c1442 = Constraint(expr= m.x410 - m.b1544 <= 0)
m.c1443 = Constraint(expr= m.x411 - m.b1545 <= 0)
m.c1444 = Constraint(expr= m.x416 - m.b1550 <= 0)
m.c1445 = Constraint(expr= m.x417 - m.b1551 <= 0)
m.c1446 = Constraint(expr= m.x418 - m.b1552 <= 0)
m.c1447 = Constraint(expr= m.x422 - m.b1574 <= 0)
m.c1448 = Constraint(expr= m.x423 - m.b1575 <= 0)
m.c1449 = Constraint(expr= m.x424 - m.b1576 <= 0)
m.c1450 = Constraint(expr= m.x425 - m.b1577 <= 0)
m.c1451 = Constraint(expr= m.x426 - m.b1578 <= 0)
m.c1452 = Constraint(expr= m.x427 - m.b1579 <= 0)
m.c1453 = Constraint(expr= m.x428 - m.b1580 <= 0)
m.c1454 = Constraint(expr= m.x429 - m.b1581 <= 0)
m.c1455 = Constraint(expr= m.x430 - m.b1582 <= 0)
m.c1456 = Constraint(expr= m.x431 - m.b1583 <= 0)
m.c1457 = Constraint(expr= m.x432 - m.b1584 <= 0)
m.c1458 = Constraint(expr= m.x433 - m.b1585 <= 0)
m.c1459 = Constraint(expr= m.x434 - m.b1586 <= 0)
m.c1460 = Constraint(expr= m.x435 - m.b1587 <= 0)
m.c1461 = Constraint(expr= m.x436 - m.b1588 <= 0)
m.c1462 = Constraint(expr= m.x437 - m.b1589 <= 0)
m.c1463 = Constraint(expr= m.x438 - m.b1590 <= 0)
m.c1464 = Constraint(expr= m.x439 - m.b1591 <= 0)
m.c1465 = Constraint(expr= m.x440 - m.b1592 <= 0)
m.c1466 = Constraint(expr= m.x441 - m.b1593 <= 0)
m.c1467 = Constraint(expr= m.x442 - m.b1594 <= 0)
m.c1468 = Constraint(expr= m.x443 - m.b1595 <= 0)
m.c1469 = Constraint(expr= m.x444 - m.b1596 <= 0)
m.c1470 = Constraint(expr= m.x445 - m.b1597 <= 0)
m.c1471 = Constraint(expr= m.x446 - m.b1622 <= 0)
m.c1472 = Constraint(expr= m.x447 - m.b1623 <= 0)
m.c1473 = Constraint(expr= m.x448 - m.b1624 <= 0)
m.c1474 = Constraint(expr= m.x449 - m.b1625 <= 0)
m.c1475 = Constraint(expr= m.x450 - m.b1626 <= 0)
m.c1476 = Constraint(expr= m.x451 - m.b1627 <= 0)
m.c1477 = Constraint(expr= m.x452 - m.b1628 <= 0)
m.c1478 = Constraint(expr= m.x453 - m.b1629 <= 0)
m.c1479 = Constraint(expr= m.x454 - m.b1630 <= 0)
m.c1480 = Constraint(expr= m.x455 - m.b1631 <= 0)
m.c1481 = Constraint(expr= m.x456 - m.b1632 <= 0)
m.c1482 = Constraint(expr= m.x457 - m.b1633 <= 0)
m.c1483 = Constraint(expr= m.x458 - m.b1634 <= 0)
m.c1484 = Constraint(expr= m.x459 - m.b1635 <= 0)
m.c1485 = Constraint(expr= m.x460 - m.b1636 <= 0)
m.c1486 = Constraint(expr= m.x461 - m.b1637 <= 0)
m.c1487 = Constraint(expr= m.x462 - m.b1638 <= 0)
m.c1488 = Constraint(expr= m.x463 - m.b1639 <= 0)
m.c1489 = Constraint(expr= m.x464 - m.b1676 <= 0)
m.c1490 = Constraint(expr= m.x465 - m.b1677 <= 0)
m.c1491 = Constraint(expr= m.x466 - m.b1678 <= 0)
m.c1492 = Constraint(expr= m.x467 - m.b1679 <= 0)
m.c1493 = Constraint(expr= m.x468 - m.b1680 <= 0)
m.c1494 = Constraint(expr= m.x469 - m.b1681 <= 0)
m.c1495 = Constraint(expr= m.x470 - m.b1538 <= 0)
m.c1496 = Constraint(expr= m.x476 - m.b1568 <= 0)
m.c1497 = Constraint(expr= m.x477 - m.b1569 <= 0)
m.c1498 = Constraint(expr= m.x478 - m.b1570 <= 0)
m.c1499 = Constraint(expr= m.x479 - m.b1571 <= 0)
m.c1500 = Constraint(expr= m.x480 - m.b1572 <= 0)
m.c1501 = Constraint(expr= m.x481 - m.b1573 <= 0)
m.c1502 = Constraint(expr= m.x482 - m.b1538 <= 0)
m.c1503 = Constraint(expr= m.x488 - m.b1562 <= 0)
m.c1504 = Constraint(expr= m.x489 - m.b1563 <= 0)
m.c1505 = Constraint(expr= m.x490 - m.b1564 <= 0)
m.c1506 = Constraint(expr= m.x491 - m.b1565 <= 0)
m.c1507 = Constraint(expr= m.x492 - m.b1566 <= 0)
m.c1508 = Constraint(expr= m.x494 - m.b1604 <= 0)
m.c1509 = Constraint(expr= m.x495 - m.b1605 <= 0)
m.c1510 = Constraint(expr= m.x496 - m.b1606 <= 0)
m.c1511 = Constraint(expr= m.x497 - m.b1607 <= 0)
m.c1512 = Constraint(expr= m.x498 - m.b1608 <= 0)
m.c1513 = Constraint(expr= m.x499 - m.b1609 <= 0)
m.c1514 = Constraint(expr= m.x500 - m.b1670 <= 0)
m.c1515 = Constraint(expr= m.x501 - m.b1671 <= 0)
m.c1516 = Constraint(expr= m.x502 - m.b1672 <= 0)
m.c1517 = Constraint(expr= m.x503 - m.b1673 <= 0)
m.c1518 = Constraint(expr= m.x504 - m.b1674 <= 0)
m.c1519 = Constraint(expr= m.x505 - m.b1675 <= 0)
m.c1520 = Constraint(expr= m.x506 - m.b1562 <= 0)
m.c1521 = Constraint(expr= m.x507 - m.b1563 <= 0)
m.c1522 = Constraint(expr= m.x508 - m.b1564 <= 0)
m.c1523 = Constraint(expr= m.x509 - m.b1565 <= 0)
m.c1524 = Constraint(expr= m.x510 - m.b1566 <= 0)
m.c1525 = Constraint(expr= m.x512 - m.b1604 <= 0)
m.c1526 = Constraint(expr= m.x513 - m.b1605 <= 0)
m.c1527 = Constraint(expr= m.x514 - m.b1606 <= 0)
m.c1528 = Constraint(expr= m.x515 - m.b1607 <= 0)
m.c1529 = Constraint(expr= m.x516 - m.b1608 <= 0)
m.c1530 = Constraint(expr= m.x517 - m.b1609 <= 0)
m.c1531 = Constraint(expr= m.x518 - m.b1544 <= 0)
m.c1532 = Constraint(expr= m.x519 - m.b1545 <= 0)
m.c1533 = Constraint(expr= m.x524 - m.b1550 <= 0)
m.c1534 = Constraint(expr= m.x525 - m.b1551 <= 0)
m.c1535 = Constraint(expr= m.x526 - m.b1552 <= 0)
m.c1536 = Constraint(expr= m.x530 - m.b1616 <= 0)
m.c1537 = Constraint(expr= m.x531 - m.b1617 <= 0)
m.c1538 = Constraint(expr= m.x532 - m.b1618 <= 0)
m.c1539 = Constraint(expr= m.x533 - m.b1619 <= 0)
m.c1540 = Constraint(expr= m.x534 - m.b1620 <= 0)
m.c1541 = Constraint(expr= m.x535 - m.b1621 <= 0)
m.c1542 = Constraint(expr= m.x536 - m.b1544 <= 0)
m.c1543 = Constraint(expr= m.x537 - m.b1545 <= 0)
m.c1544 = Constraint(expr= m.x542 - m.b1550 <= 0)
m.c1545 = Constraint(expr= m.x543 - m.b1551 <= 0)
m.c1546 = Constraint(expr= m.x544 - m.b1552 <= 0)
m.c1547 = Constraint(expr= m.x548 - m.b1574 <= 0)
m.c1548 = Constraint(expr= m.x549 - m.b1575 <= 0)
m.c1549 = Constraint(expr= m.x550 - m.b1576 <= 0)
m.c1550 = Constraint(expr= m.x551 - m.b1577 <= 0)
m.c1551 = Constraint(expr= m.x552 - m.b1578 <= 0)
m.c1552 = Constraint(expr= m.x553 - m.b1579 <= 0)
m.c1553 = Constraint(expr= m.x554 - m.b1622 <= 0)
m.c1554 = Constraint(expr= m.x555 - m.b1623 <= 0)
m.c1555 = Constraint(expr= m.x556 - m.b1624 <= 0)
m.c1556 = Constraint(expr= m.x557 - m.b1625 <= 0)
m.c1557 = Constraint(expr= m.x558 - m.b1626 <= 0)
m.c1558 = Constraint(expr= m.x559 - m.b1627 <= 0)
m.c1559 = Constraint(expr= m.x560 - m.b1544 <= 0)
m.c1560 = Constraint(expr= m.x561 - m.b1545 <= 0)
m.c1561 = Constraint(expr= m.x566 - m.b1550 <= 0)
m.c1562 = Constraint(expr= m.x567 - m.b1551 <= 0)
m.c1563 = Constraint(expr= m.x568 - m.b1552 <= 0)
m.c1564 = Constraint(expr= m.x572 - m.b1574 <= 0)
m.c1565 = Constraint(expr= m.x573 - m.b1575 <= 0)
m.c1566 = Constraint(expr= m.x574 - m.b1576 <= 0)
m.c1567 = Constraint(expr= m.x575 - m.b1577 <= 0)
m.c1568 = Constraint(expr= m.x576 - m.b1578 <= 0)
m.c1569 = Constraint(expr= m.x577 - m.b1579 <= 0)
m.c1570 = Constraint(expr= m.x578 - m.b1622 <= 0)
m.c1571 = Constraint(expr= m.x579 - m.b1623 <= 0)
m.c1572 = Constraint(expr= m.x580 - m.b1624 <= 0)
m.c1573 = Constraint(expr= m.x581 - m.b1625 <= 0)
m.c1574 = Constraint(expr= m.x582 - m.b1626 <= 0)
m.c1575 = Constraint(expr= m.x583 - m.b1627 <= 0)
m.c1576 = Constraint(expr= m.x584 - m.b1628 <= 0)
m.c1577 = Constraint(expr= m.x585 - m.b1629 <= 0)
m.c1578 = Constraint(expr= m.x586 - m.b1630 <= 0)
m.c1579 = Constraint(expr= m.x587 - m.b1631 <= 0)
m.c1580 = Constraint(expr= m.x588 - m.b1632 <= 0)
m.c1581 = Constraint(expr= m.x589 - m.b1633 <= 0)
m.c1582 = Constraint(expr= m.x590 - m.b1676 <= 0)
m.c1583 = Constraint(expr= m.x591 - m.b1677 <= 0)
m.c1584 = Constraint(expr= m.x592 - m.b1678 <= 0)
m.c1585 = Constraint(expr= m.x593 - m.b1679 <= 0)
m.c1586 = Constraint(expr= m.x594 - m.b1680 <= 0)
m.c1587 = Constraint(expr= m.x595 - m.b1681 <= 0)
m.c1588 = Constraint(expr= m.x596 - m.b1544 <= 0)
m.c1589 = Constraint(expr= m.x597 - m.b1545 <= 0)
m.c1590 = Constraint(expr= m.x602 - m.b1574 <= 0)
m.c1591 = Constraint(expr= m.x603 - m.b1575 <= 0)
m.c1592 = Constraint(expr= m.x604 - m.b1576 <= 0)
m.c1593 = Constraint(expr= m.x605 - m.b1577 <= 0)
m.c1594 = Constraint(expr= m.x606 - m.b1578 <= 0)
m.c1595 = Constraint(expr= m.x607 - m.b1579 <= 0)
m.c1596 = Constraint(expr= m.x608 - m.b1580 <= 0)
m.c1597 = Constraint(expr= m.x609 - m.b1581 <= 0)
m.c1598 = Constraint(expr= m.x610 - m.b1582 <= 0)
m.c1599 = Constraint(expr= m.x611 - m.b1583 <= 0)
m.c1600 = Constraint(expr= m.x612 - m.b1584 <= 0)
m.c1601 = Constraint(expr= m.x613 - m.b1585 <= 0)
m.c1602 = Constraint(expr= m.x614 - m.b1586 <= 0)
m.c1603 = Constraint(expr= m.x615 - m.b1587 <= 0)
m.c1604 = Constraint(expr= m.x616 - m.b1588 <= 0)
m.c1605 = Constraint(expr= m.x617 - m.b1589 <= 0)
m.c1606 = Constraint(expr= m.x618 - m.b1590 <= 0)
m.c1607 = Constraint(expr= m.x619 - m.b1591 <= 0)
m.c1608 = Constraint(expr= m.x620 - m.b1592 <= 0)
m.c1609 = Constraint(expr= m.x621 - m.b1593 <= 0)
m.c1610 = Constraint(expr= m.x622 - m.b1594 <= 0)
m.c1611 = Constraint(expr= m.x623 - m.b1595 <= 0)
m.c1612 = Constraint(expr= m.x624 - m.b1596 <= 0)
m.c1613 = Constraint(expr= m.x625 - m.b1597 <= 0)
m.c1614 = Constraint(expr= m.x626 - m.b1598 <= 0)
m.c1615 = Constraint(expr= m.x627 - m.b1599 <= 0)
m.c1616 = Constraint(expr= m.x628 - m.b1600 <= 0)
m.c1617 = Constraint(expr= m.x629 - m.b1601 <= 0)
m.c1618 = Constraint(expr= m.x630 - m.b1602 <= 0)
m.c1619 = Constraint(expr= m.x631 - m.b1603 <= 0)
m.c1620 = Constraint(expr= m.x632 - m.b1628 <= 0)
m.c1621 = Constraint(expr= m.x633 - m.b1629 <= 0)
m.c1622 = Constraint(expr= m.x634 - m.b1630 <= 0)
m.c1623 = Constraint(expr= m.x635 - m.b1631 <= 0)
m.c1624 = Constraint(expr= m.x636 - m.b1632 <= 0)
m.c1625 = Constraint(expr= m.x637 - m.b1633 <= 0)
m.c1626 = Constraint(expr= m.x638 - m.b1634 <= 0)
m.c1627 = Constraint(expr= m.x639 - m.b1635 <= 0)
m.c1628 = Constraint(expr= m.x640 - m.b1636 <= 0)
m.c1629 = Constraint(expr= m.x641 - m.b1637 <= 0)
m.c1630 = Constraint(expr= m.x642 - m.b1638 <= 0)
m.c1631 = Constraint(expr= m.x643 - m.b1639 <= 0)
m.c1632 = Constraint(expr= m.x644 - m.b1676 <= 0)
m.c1633 = Constraint(expr= m.x645 - m.b1677 <= 0)
m.c1634 = Constraint(expr= m.x646 - m.b1678 <= 0)
m.c1635 = Constraint(expr= m.x647 - m.b1679 <= 0)
m.c1636 = Constraint(expr= m.x648 - m.b1680 <= 0)
m.c1637 = Constraint(expr= m.x649 - m.b1681 <= 0)
m.c1638 = Constraint(expr= m.x650 - m.b1538 <= 0)
m.c1639 = Constraint(expr= m.x656 - m.b1544 <= 0)
m.c1640 = Constraint(expr= m.x657 - m.b1545 <= 0)
m.c1641 = Constraint(expr= m.x662 - m.b1556 <= 0)
m.c1642 = Constraint(expr= m.x663 - m.b1557 <= 0)
m.c1643 = Constraint(expr= m.x664 - m.b1558 <= 0)
m.c1644 = Constraint(expr= m.x665 - m.b1559 <= 0)
m.c1645 = Constraint(expr= m.x668 - m.b1562 <= 0)
m.c1646 = Constraint(expr= m.x669 - m.b1563 <= 0)
m.c1647 = Constraint(expr= m.x670 - m.b1564 <= 0)
m.c1648 = Constraint(expr= m.x671 - m.b1565 <= 0)
m.c1649 = Constraint(expr= m.x672 - m.b1566 <= 0)
m.c1650 = Constraint(expr= m.x674 - m.b1604 <= 0)
m.c1651 = Constraint(expr= m.x675 - m.b1605 <= 0)
m.c1652 = Constraint(expr= m.x676 - m.b1606 <= 0)
m.c1653 = Constraint(expr= m.x677 - m.b1607 <= 0)
m.c1654 = Constraint(expr= m.x678 - m.b1608 <= 0)
m.c1655 = Constraint(expr= m.x679 - m.b1609 <= 0)
m.c1656 = Constraint(expr= m.x680 - m.b1616 <= 0)
m.c1657 = Constraint(expr= m.x681 - m.b1617 <= 0)
m.c1658 = Constraint(expr= m.x682 - m.b1618 <= 0)
m.c1659 = Constraint(expr= m.x683 - m.b1619 <= 0)
m.c1660 = Constraint(expr= m.x684 - m.b1620 <= 0)
m.c1661 = Constraint(expr= m.x685 - m.b1621 <= 0)
m.c1662 = Constraint(expr= m.x686 - m.b1538 <= 0)
m.c1663 = Constraint(expr= m.x692 - m.b1544 <= 0)
m.c1664 = Constraint(expr= m.x693 - m.b1545 <= 0)
m.c1665 = Constraint(expr= m.x698 - m.b1556 <= 0)
m.c1666 = Constraint(expr= m.x699 - m.b1557 <= 0)
m.c1667 = Constraint(expr= m.x700 - m.b1558 <= 0)
m.c1668 = Constraint(expr= m.x701 - m.b1559 <= 0)
m.c1669 = Constraint(expr= m.x704 - m.b1562 <= 0)
m.c1670 = Constraint(expr= m.x705 - m.b1563 <= 0)
m.c1671 = Constraint(expr= m.x706 - m.b1564 <= 0)
m.c1672 = Constraint(expr= m.x707 - m.b1565 <= 0)
m.c1673 = Constraint(expr= m.x708 - m.b1566 <= 0)
m.c1674 = Constraint(expr= m.x710 - m.b1604 <= 0)
m.c1675 = Constraint(expr= m.x711 - m.b1605 <= 0)
m.c1676 = Constraint(expr= m.x712 - m.b1606 <= 0)
m.c1677 = Constraint(expr= m.x713 - m.b1607 <= 0)
m.c1678 = Constraint(expr= m.x714 - m.b1608 <= 0)
m.c1679 = Constraint(expr= m.x715 - m.b1609 <= 0)
m.c1680 = Constraint(expr= m.x716 - m.b1616 <= 0)
m.c1681 = Constraint(expr= m.x717 - m.b1617 <= 0)
m.c1682 = Constraint(expr= m.x718 - m.b1618 <= 0)
m.c1683 = Constraint(expr= m.x719 - m.b1619 <= 0)
m.c1684 = Constraint(expr= m.x720 - m.b1620 <= 0)
m.c1685 = Constraint(expr= m.x721 - m.b1621 <= 0)
m.c1686 = Constraint(expr= m.x722 - m.b1652 <= 0)
m.c1687 = Constraint(expr= m.x723 - m.b1653 <= 0)
m.c1688 = Constraint(expr= m.x724 - m.b1654 <= 0)
m.c1689 = Constraint(expr= m.x725 - m.b1655 <= 0)
m.c1690 = Constraint(expr= m.x726 - m.b1656 <= 0)
m.c1691 = Constraint(expr= m.x727 - m.b1657 <= 0)
m.c1692 = Constraint(expr= m.x728 - m.b1538 <= 0)
m.c1693 = Constraint(expr= m.x734 - m.b1556 <= 0)
m.c1694 = Constraint(expr= m.x735 - m.b1557 <= 0)
m.c1695 = Constraint(expr= m.x736 - m.b1558 <= 0)
m.c1696 = Constraint(expr= m.x737 - m.b1559 <= 0)
m.c1697 = Constraint(expr= m.x740 - m.b1562 <= 0)
m.c1698 = Constraint(expr= m.x741 - m.b1563 <= 0)
m.c1699 = Constraint(expr= m.x742 - m.b1564 <= 0)
m.c1700 = Constraint(expr= m.x743 - m.b1565 <= 0)
m.c1701 = Constraint(expr= m.x744 - m.b1566 <= 0)
m.c1702 = Constraint(expr= m.x746 - m.b1574 <= 0)
m.c1703 = Constraint(expr= m.x747 - m.b1575 <= 0)
m.c1704 = Constraint(expr= m.x748 - m.b1576 <= 0)
m.c1705 = Constraint(expr= m.x749 - m.b1577 <= 0)
m.c1706 = Constraint(expr= m.x750 - m.b1578 <= 0)
m.c1707 = Constraint(expr= m.x751 - m.b1579 <= 0)
m.c1708 = Constraint(expr= m.x752 - m.b1604 <= 0)
m.c1709 = Constraint(expr= m.x753 - m.b1605 <= 0)
m.c1710 = Constraint(expr= m.x754 - m.b1606 <= 0)
m.c1711 = Constraint(expr= m.x755 - m.b1607 <= 0)
m.c1712 = Constraint(expr= m.x756 - m.b1608 <= 0)
m.c1713 = Constraint(expr= m.x757 - m.b1609 <= 0)
m.c1714 = Constraint(expr= m.x758 - m.b1616 <= 0)
m.c1715 = Constraint(expr= m.x759 - m.b1617 <= 0)
m.c1716 = Constraint(expr= m.x760 - m.b1618 <= 0)
m.c1717 = Constraint(expr= m.x761 - m.b1619 <= 0)
m.c1718 = Constraint(expr= m.x762 - m.b1620 <= 0)
m.c1719 = Constraint(expr= m.x763 - m.b1621 <= 0)
m.c1720 = Constraint(expr= m.x764 - m.b1652 <= 0)
m.c1721 = Constraint(expr= m.x765 - m.b1653 <= 0)
m.c1722 = Constraint(expr= m.x766 - m.b1654 <= 0)
m.c1723 = Constraint(expr= m.x767 - m.b1655 <= 0)
m.c1724 = Constraint(expr= m.x768 - m.b1656 <= 0)
m.c1725 = Constraint(expr= m.x769 - m.b1657 <= 0)
m.c1726 = Constraint(expr= m.x770 - m.b1658 <= 0)
m.c1727 = Constraint(expr= m.x771 - m.b1659 <= 0)
m.c1728 = Constraint(expr= m.x772 - m.b1660 <= 0)
m.c1729 = Constraint(expr= m.x773 - m.b1661 <= 0)
m.c1730 = Constraint(expr= m.x774 - m.b1662 <= 0)
m.c1731 = Constraint(expr= m.x775 - m.b1663 <= 0)
m.c1732 = Constraint(expr= m.x776 - m.b1544 <= 0)
m.c1733 = Constraint(expr= m.x777 - m.b1545 <= 0)
m.c1734 = Constraint(expr= m.x782 - m.b1574 <= 0)
m.c1735 = Constraint(expr= m.x783 - m.b1575 <= 0)
m.c1736 = Constraint(expr= m.x784 - m.b1576 <= 0)
m.c1737 = Constraint(expr= m.x785 - m.b1577 <= 0)
m.c1738 = Constraint(expr= m.x786 - m.b1578 <= 0)
m.c1739 = Constraint(expr= m.x787 - m.b1579 <= 0)
m.c1740 = Constraint(expr= m.x788 - m.b1628 <= 0)
m.c1741 = Constraint(expr= m.x789 - m.b1629 <= 0)
m.c1742 = Constraint(expr= m.x790 - m.b1630 <= 0)
m.c1743 = Constraint(expr= m.x791 - m.b1631 <= 0)
m.c1744 = Constraint(expr= m.x792 - m.b1632 <= 0)
m.c1745 = Constraint(expr= m.x793 - m.b1633 <= 0)
m.c1746 = Constraint(expr= m.x794 - m.b1538 <= 0)
m.c1747 = Constraint(expr= m.x800 - m.b1544 <= 0)
m.c1748 = Constraint(expr= m.x801 - m.b1545 <= 0)
m.c1749 = Constraint(expr= m.x806 - m.b1556 <= 0)
m.c1750 = Constraint(expr= m.x807 - m.b1557 <= 0)
m.c1751 = Constraint(expr= m.x808 - m.b1558 <= 0)
m.c1752 = Constraint(expr= m.x809 - m.b1559 <= 0)
m.c1753 = Constraint(expr= m.x812 - m.b1562 <= 0)
m.c1754 = Constraint(expr= m.x813 - m.b1563 <= 0)
m.c1755 = Constraint(expr= m.x814 - m.b1564 <= 0)
m.c1756 = Constraint(expr= m.x815 - m.b1565 <= 0)
m.c1757 = Constraint(expr= m.x816 - m.b1566 <= 0)
m.c1758 = Constraint(expr= m.x818 - m.b1616 <= 0)
m.c1759 = Constraint(expr= m.x819 - m.b1617 <= 0)
m.c1760 = Constraint(expr= m.x820 - m.b1618 <= 0)
m.c1761 = Constraint(expr= m.x821 - m.b1619 <= 0)
m.c1762 = Constraint(expr= m.x822 - m.b1620 <= 0)
m.c1763 = Constraint(expr= m.x823 - m.b1621 <= 0)
m.c1764 = Constraint(expr= m.x824 - m.b1652 <= 0)
m.c1765 = Constraint(expr= m.x825 - m.b1653 <= 0)
m.c1766 = Constraint(expr= m.x826 - m.b1654 <= 0)
m.c1767 = Constraint(expr= m.x827 - m.b1655 <= 0)
m.c1768 = Constraint(expr= m.x828 - m.b1656 <= 0)
m.c1769 = Constraint(expr= m.x829 - m.b1657 <= 0)
m.c1770 = Constraint(expr= m.x830 - m.b1658 <= 0)
m.c1771 = Constraint(expr= m.x831 - m.b1659 <= 0)
m.c1772 = Constraint(expr= m.x832 - m.b1660 <= 0)
m.c1773 = Constraint(expr= m.x833 - m.b1661 <= 0)
m.c1774 = Constraint(expr= m.x834 - m.b1662 <= 0)
m.c1775 = Constraint(expr= m.x835 - m.b1663 <= 0)
m.c1776 = Constraint(expr= m.x836 - m.b1664 <= 0)
m.c1777 = Constraint(expr= m.x837 - m.b1665 <= 0)
m.c1778 = Constraint(expr= m.x838 - m.b1666 <= 0)
m.c1779 = Constraint(expr= m.x839 - m.b1667 <= 0)
m.c1780 = Constraint(expr= m.x840 - m.b1668 <= 0)
m.c1781 = Constraint(expr= m.x841 - m.b1669 <= 0)
m.c1782 = Constraint(expr= m.x842 - m.b1538 <= 0)
m.c1783 = Constraint(expr= m.x848 - m.b1556 <= 0)
m.c1784 = Constraint(expr= m.x849 - m.b1557 <= 0)
m.c1785 = Constraint(expr= m.x850 - m.b1558 <= 0)
m.c1786 = Constraint(expr= m.x851 - m.b1559 <= 0)
m.c1787 = Constraint(expr= m.x854 - m.b1568 <= 0)
m.c1788 = Constraint(expr= m.x855 - m.b1569 <= 0)
m.c1789 = Constraint(expr= m.x856 - m.b1570 <= 0)
m.c1790 = Constraint(expr= m.x857 - m.b1571 <= 0)
m.c1791 = Constraint(expr= m.x858 - m.b1572 <= 0)
m.c1792 = Constraint(expr= m.x859 - m.b1573 <= 0)
m.c1793 = Constraint(expr= m.x860 - m.b1670 <= 0)
m.c1794 = Constraint(expr= m.x861 - m.b1671 <= 0)
m.c1795 = Constraint(expr= m.x862 - m.b1672 <= 0)
m.c1796 = Constraint(expr= m.x863 - m.b1673 <= 0)
m.c1797 = Constraint(expr= m.x864 - m.b1674 <= 0)
m.c1798 = Constraint(expr= m.x865 - m.b1675 <= 0)
m.c1799 = Constraint(expr= m.x866 - m.b1670 <= 0)
m.c1800 = Constraint(expr= m.x867 - m.b1671 <= 0)
m.c1801 = Constraint(expr= m.x868 - m.b1672 <= 0)
m.c1802 = Constraint(expr= m.x869 - m.b1673 <= 0)
m.c1803 = Constraint(expr= m.x870 - m.b1674 <= 0)
m.c1804 = Constraint(expr= m.x871 - m.b1675 <= 0)
m.c1805 = Constraint(expr= m.x872 - m.b1694 <= 0)
m.c1806 = Constraint(expr= m.x873 - m.b1695 <= 0)
m.c1807 = Constraint(expr= m.x874 - m.b1696 <= 0)
m.c1808 = Constraint(expr= m.x875 - m.b1697 <= 0)
m.c1809 = Constraint(expr= m.x876 - m.b1698 <= 0)
m.c1810 = Constraint(expr= m.x877 - m.b1699 <= 0)
m.c1811 = Constraint(expr= m.x878 - m.b1670 <= 0)
m.c1812 = Constraint(expr= m.x879 - m.b1671 <= 0)
m.c1813 = Constraint(expr= m.x880 - m.b1672 <= 0)
m.c1814 = Constraint(expr= m.x881 - m.b1673 <= 0)
m.c1815 = Constraint(expr= m.x882 - m.b1674 <= 0)
m.c1816 = Constraint(expr= m.x883 - m.b1675 <= 0)
m.c1817 = Constraint(expr= m.x884 - m.b1694 <= 0)
m.c1818 = Constraint(expr= m.x885 - m.b1695 <= 0)
m.c1819 = Constraint(expr= m.x886 - m.b1696 <= 0)
m.c1820 = Constraint(expr= m.x887 - m.b1697 <= 0)
m.c1821 = Constraint(expr= m.x888 - m.b1698 <= 0)
m.c1822 = Constraint(expr= m.x889 - m.b1699 <= 0)
m.c1823 = Constraint(expr= m.x890 - m.b1700 <= 0)
m.c1824 = Constraint(expr= m.x891 - m.b1701 <= 0)
m.c1825 = Constraint(expr= m.x892 - m.b1702 <= 0)
m.c1826 = Constraint(expr= m.x893 - m.b1703 <= 0)
m.c1827 = Constraint(expr= m.x894 - m.b1704 <= 0)
m.c1828 = Constraint(expr= m.x895 - m.b1705 <= 0)
m.c1829 = Constraint(expr= m.x896 - m.b1670 <= 0)
m.c1830 = Constraint(expr= m.x897 - m.b1671 <= 0)
m.c1831 = Constraint(expr= m.x898 - m.b1672 <= 0)
m.c1832 = Constraint(expr= m.x899 - m.b1673 <= 0)
m.c1833 = Constraint(expr= m.x900 - m.b1674 <= 0)
m.c1834 = Constraint(expr= m.x901 - m.b1675 <= 0)
m.c1835 = Constraint(expr= m.x902 - m.b1694 <= 0)
m.c1836 = Constraint(expr= m.x903 - m.b1695 <= 0)
m.c1837 = Constraint(expr= m.x904 - m.b1696 <= 0)
m.c1838 = Constraint(expr= m.x905 - m.b1697 <= 0)
m.c1839 = Constraint(expr= m.x906 - m.b1698 <= 0)
m.c1840 = Constraint(expr= m.x907 - m.b1699 <= 0)
m.c1841 = Constraint(expr= m.x908 - m.b1700 <= 0)
m.c1842 = Constraint(expr= m.x909 - m.b1701 <= 0)
m.c1843 = Constraint(expr= m.x910 - m.b1702 <= 0)
m.c1844 = Constraint(expr= m.x911 - m.b1703 <= 0)
m.c1845 = Constraint(expr= m.x912 - m.b1704 <= 0)
m.c1846 = Constraint(expr= m.x913 - m.b1705 <= 0)
m.c1847 = Constraint(expr= m.x914 - m.b1706 <= 0)
m.c1848 = Constraint(expr= m.x915 - m.b1707 <= 0)
m.c1849 = Constraint(expr= m.x916 - m.b1708 <= 0)
m.c1850 = Constraint(expr= m.x917 - m.b1709 <= 0)
m.c1851 = Constraint(expr= m.x918 - m.b1710 <= 0)
m.c1852 = Constraint(expr= m.x919 - m.b1711 <= 0)
m.c1853 = Constraint(expr= m.x920 - m.b1670 <= 0)
m.c1854 = Constraint(expr= m.x921 - m.b1671 <= 0)
m.c1855 = Constraint(expr= m.x922 - m.b1672 <= 0)
m.c1856 = Constraint(expr= m.x923 - m.b1673 <= 0)
m.c1857 = Constraint(expr= m.x924 - m.b1674 <= 0)
m.c1858 = Constraint(expr= m.x925 - m.b1675 <= 0)
m.c1859 = Constraint(expr= m.x926 - m.b1694 <= 0)
m.c1860 = Constraint(expr= m.x927 - m.b1695 <= 0)
m.c1861 = Constraint(expr= m.x928 - m.b1696 <= 0)
m.c1862 = Constraint(expr= m.x929 - m.b1697 <= 0)
m.c1863 = Constraint(expr= m.x930 - m.b1698 <= 0)
m.c1864 = Constraint(expr= m.x931 - m.b1699 <= 0)
m.c1865 = Constraint(expr= m.x932 - m.b1700 <= 0)
m.c1866 = Constraint(expr= m.x933 - m.b1701 <= 0)
m.c1867 = Constraint(expr= m.x934 - m.b1702 <= 0)
m.c1868 = Constraint(expr= m.x935 - m.b1703 <= 0)
m.c1869 = Constraint(expr= m.x936 - m.b1704 <= 0)
m.c1870 = Constraint(expr= m.x937 - m.b1705 <= 0)
m.c1871 = Constraint(expr= m.x938 - m.b1706 <= 0)
m.c1872 = Constraint(expr= m.x939 - m.b1707 <= 0)
m.c1873 = Constraint(expr= m.x940 - m.b1708 <= 0)
m.c1874 = Constraint(expr= m.x941 - m.b1709 <= 0)
m.c1875 = Constraint(expr= m.x942 - m.b1710 <= 0)
m.c1876 = Constraint(expr= m.x943 - m.b1711 <= 0)
m.c1877 = Constraint(expr= m.x944 - m.b1712 <= 0)
m.c1878 = Constraint(expr= m.x945 - m.b1713 <= 0)
m.c1879 = Constraint(expr= m.x946 - m.b1714 <= 0)
m.c1880 = Constraint(expr= m.x947 - m.b1715 <= 0)
m.c1881 = Constraint(expr= m.x948 - m.b1716 <= 0)
m.c1882 = Constraint(expr= m.x949 - m.b1717 <= 0)
m.c1883 = Constraint(expr= m.x950 - m.b1670 <= 0)
m.c1884 = Constraint(expr= m.x951 - m.b1671 <= 0)
m.c1885 = Constraint(expr= m.x952 - m.b1672 <= 0)
m.c1886 = Constraint(expr= m.x953 - m.b1673 <= 0)
m.c1887 = Constraint(expr= m.x954 - m.b1674 <= 0)
m.c1888 = Constraint(expr= m.x955 - m.b1675 <= 0)
m.c1889 = Constraint(expr= m.x956 - m.b1694 <= 0)
m.c1890 = Constraint(expr= m.x957 - m.b1695 <= 0)
m.c1891 = Constraint(expr= m.x958 - m.b1696 <= 0)
m.c1892 = Constraint(expr= m.x959 - m.b1697 <= 0)
m.c1893 = Constraint(expr= m.x960 - m.b1698 <= 0)
m.c1894 = Constraint(expr= m.x961 - m.b1699 <= 0)
m.c1895 = Constraint(expr= m.x962 - m.b1700 <= 0)
m.c1896 = Constraint(expr= m.x963 - m.b1701 <= 0)
m.c1897 = Constraint(expr= m.x964 - m.b1702 <= 0)
m.c1898 = Constraint(expr= m.x965 - m.b1703 <= 0)
m.c1899 = Constraint(expr= m.x966 - m.b1704 <= 0)
m.c1900 = Constraint(expr= m.x967 - m.b1705 <= 0)
m.c1901 = Constraint(expr= m.x968 - m.b1706 <= 0)
m.c1902 = Constraint(expr= m.x969 - m.b1707 <= 0)
m.c1903 = Constraint(expr= m.x970 - m.b1708 <= 0)
m.c1904 = Constraint(expr= m.x971 - m.b1709 <= 0)
m.c1905 = Constraint(expr= m.x972 - m.b1710 <= 0)
m.c1906 = Constraint(expr= m.x973 - m.b1711 <= 0)
m.c1907 = Constraint(expr= m.x974 - m.b1712 <= 0)
m.c1908 = Constraint(expr= m.x975 - m.b1713 <= 0)
m.c1909 = Constraint(expr= m.x976 - m.b1714 <= 0)
m.c1910 = Constraint(expr= m.x977 - m.b1715 <= 0)
m.c1911 = Constraint(expr= m.x978 - m.b1716 <= 0)
m.c1912 = Constraint(expr= m.x979 - m.b1717 <= 0)
m.c1913 = Constraint(expr= m.x980 - m.b1718 <= 0)
m.c1914 = Constraint(expr= m.x981 - m.b1719 <= 0)
m.c1915 = Constraint(expr= m.x982 - m.b1720 <= 0)
m.c1916 = Constraint(expr= m.x983 - m.b1721 <= 0)
m.c1917 = Constraint(expr= m.x984 - m.b1722 <= 0)
m.c1918 = Constraint(expr= m.x985 - m.b1723 <= 0)
m.c1919 = Constraint(expr= m.x986 - m.b1538 <= 0)
m.c1920 = Constraint(expr= m.x992 - m.b1610 <= 0)
m.c1921 = Constraint(expr= m.x993 - m.b1611 <= 0)
m.c1922 = Constraint(expr= m.x994 - m.b1612 <= 0)
m.c1923 = Constraint(expr= m.x995 - m.b1613 <= 0)
m.c1924 = Constraint(expr= m.x996 - m.b1614 <= 0)
m.c1925 = Constraint(expr= m.x997 - m.b1615 <= 0)
m.c1926 = Constraint(expr= m.x998 - m.b1538 <= 0)
m.c1927 = Constraint(expr= m.x1004 - m.b1610 <= 0)
m.c1928 = Constraint(expr= m.x1005 - m.b1611 <= 0)
m.c1929 = Constraint(expr= m.x1006 - m.b1612 <= 0)
m.c1930 = Constraint(expr= m.x1007 - m.b1613 <= 0)
m.c1931 = Constraint(expr= m.x1008 - m.b1614 <= 0)
m.c1932 = Constraint(expr= m.x1009 - m.b1615 <= 0)
m.c1933 = Constraint(expr= m.x1010 - m.b1730 <= 0)
m.c1934 = Constraint(expr= m.x1011 - m.b1731 <= 0)
m.c1935 = Constraint(expr= m.x1012 - m.b1732 <= 0)
m.c1936 = Constraint(expr= m.x1013 - m.b1733 <= 0)
m.c1937 = Constraint(expr= m.x1014 - m.b1734 <= 0)
m.c1938 = Constraint(expr= m.x1015 - m.b1735 <= 0)
m.c1939 = Constraint(expr= m.x1016 - m.b1544 <= 0)
m.c1940 = Constraint(expr= m.x1017 - m.b1545 <= 0)
m.c1941 = Constraint(expr= m.x1022 - m.b1562 <= 0)
m.c1942 = Constraint(expr= m.x1023 - m.b1563 <= 0)
m.c1943 = Constraint(expr= m.x1024 - m.b1564 <= 0)
m.c1944 = Constraint(expr= m.x1025 - m.b1565 <= 0)
m.c1945 = Constraint(expr= m.x1026 - m.b1566 <= 0)
m.c1946 = Constraint(expr= m.x1028 - m.b1616 <= 0)
m.c1947 = Constraint(expr= m.x1029 - m.b1617 <= 0)
m.c1948 = Constraint(expr= m.x1030 - m.b1618 <= 0)
m.c1949 = Constraint(expr= m.x1031 - m.b1619 <= 0)
m.c1950 = Constraint(expr= m.x1032 - m.b1620 <= 0)
m.c1951 = Constraint(expr= m.x1033 - m.b1621 <= 0)
m.c1952 = Constraint(expr= m.x1034 - m.b1652 <= 0)
m.c1953 = Constraint(expr= m.x1035 - m.b1653 <= 0)
m.c1954 = Constraint(expr= m.x1036 - m.b1654 <= 0)
m.c1955 = Constraint(expr= m.x1037 - m.b1655 <= 0)
m.c1956 = Constraint(expr= m.x1038 - m.b1656 <= 0)
m.c1957 = Constraint(expr= m.x1039 - m.b1657 <= 0)
m.c1958 = Constraint(expr= m.x1040 - m.b1658 <= 0)
m.c1959 = Constraint(expr= m.x1041 - m.b1659 <= 0)
m.c1960 = Constraint(expr= m.x1042 - m.b1660 <= 0)
m.c1961 = Constraint(expr= m.x1043 - m.b1661 <= 0)
m.c1962 = Constraint(expr= m.x1044 - m.b1662 <= 0)
m.c1963 = Constraint(expr= m.x1045 - m.b1663 <= 0)
m.c1964 = Constraint(expr= m.x1046 - m.b1664 <= 0)
m.c1965 = Constraint(expr= m.x1047 - m.b1665 <= 0)
m.c1966 = Constraint(expr= m.x1048 - m.b1666 <= 0)
m.c1967 = Constraint(expr= m.x1049 - m.b1667 <= 0)
m.c1968 = Constraint(expr= m.x1050 - m.b1668 <= 0)
m.c1969 = Constraint(expr= m.x1051 - m.b1669 <= 0)
m.c1970 = Constraint(expr= m.x1052 - m.b1682 <= 0)
m.c1971 = Constraint(expr= m.x1053 - m.b1683 <= 0)
m.c1972 = Constraint(expr= m.x1054 - m.b1684 <= 0)
m.c1973 = Constraint(expr= m.x1055 - m.b1685 <= 0)
m.c1974 = Constraint(expr= m.x1056 - m.b1686 <= 0)
m.c1975 = Constraint(expr= m.x1057 - m.b1687 <= 0)
m.c1976 = Constraint(expr= m.x1058 - m.b1544 <= 0)
m.c1977 = Constraint(expr= m.x1059 - m.b1545 <= 0)
m.c1978 = Constraint(expr= m.x1064 - m.b1574 <= 0)
m.c1979 = Constraint(expr= m.x1065 - m.b1575 <= 0)
m.c1980 = Constraint(expr= m.x1066 - m.b1576 <= 0)
m.c1981 = Constraint(expr= m.x1067 - m.b1577 <= 0)
m.c1982 = Constraint(expr= m.x1068 - m.b1578 <= 0)
m.c1983 = Constraint(expr= m.x1069 - m.b1579 <= 0)
m.c1984 = Constraint(expr= m.x1070 - m.b1580 <= 0)
m.c1985 = Constraint(expr= m.x1071 - m.b1581 <= 0)
m.c1986 = Constraint(expr= m.x1072 - m.b1582 <= 0)
m.c1987 = Constraint(expr= m.x1073 - m.b1583 <= 0)
m.c1988 = Constraint(expr= m.x1074 - m.b1584 <= 0)
m.c1989 = Constraint(expr= m.x1075 - m.b1585 <= 0)
m.c1990 = Constraint(expr= m.x1076 - m.b1586 <= 0)
m.c1991 = Constraint(expr= m.x1077 - m.b1587 <= 0)
m.c1992 = Constraint(expr= m.x1078 - m.b1588 <= 0)
m.c1993 = Constraint(expr= m.x1079 - m.b1589 <= 0)
m.c1994 = Constraint(expr= m.x1080 - m.b1590 <= 0)
m.c1995 = Constraint(expr= m.x1081 - m.b1591 <= 0)
m.c1996 = Constraint(expr= m.x1082 - m.b1592 <= 0)
m.c1997 = Constraint(expr= m.x1083 - m.b1593 <= 0)
m.c1998 = Constraint(expr= m.x1084 - m.b1594 <= 0)
m.c1999 = Constraint(expr= m.x1085 - m.b1595 <= 0)
m.c2000 = Constraint(expr= m.x1086 - m.b1596 <= 0)
m.c2001 = Constraint(expr= m.x1087 - m.b1597 <= 0)
m.c2002 = Constraint(expr= m.x1088 - m.b1598 <= 0)
m.c2003 = Constraint(expr= m.x1089 - m.b1599 <= 0)
m.c2004 = Constraint(expr= m.x1090 - m.b1600 <= 0)
m.c2005 = Constraint(expr= m.x1091 - m.b1601 <= 0)
m.c2006 = Constraint(expr= m.x1092 - m.b1602 <= 0)
m.c2007 = Constraint(expr= m.x1093 - m.b1603 <= 0)
m.c2008 = Constraint(expr= m.x1094 - m.b1646 <= 0)
m.c2009 = Constraint(expr= m.x1095 - m.b1647 <= 0)
m.c2010 = Constraint(expr= m.x1096 - m.b1648 <= 0)
m.c2011 = Constraint(expr= m.x1097 - m.b1649 <= 0)
m.c2012 = Constraint(expr= m.x1098 - m.b1650 <= 0)
m.c2013 = Constraint(expr= m.x1099 - m.b1651 <= 0)
m.c2014 = Constraint(expr= m.x1100 - m.b1538 <= 0)
m.c2015 = Constraint(expr= m.x1106 - m.b1688 <= 0)
m.c2016 = Constraint(expr= m.x1107 - m.b1689 <= 0)
m.c2017 = Constraint(expr= m.x1108 - m.b1690 <= 0)
m.c2018 = Constraint(expr= m.x1109 - m.b1691 <= 0)
m.c2019 = Constraint(expr= m.x1110 - m.b1692 <= 0)
m.c2020 = Constraint(expr= m.x1111 - m.b1693 <= 0)
m.c2021 = Constraint(expr= m.x1112 - m.b1538 <= 0)
m.c2022 = Constraint(expr= m.x1118 - m.b1688 <= 0)
m.c2023 = Constraint(expr= m.x1119 - m.b1689 <= 0)
m.c2024 = Constraint(expr= m.x1120 - m.b1690 <= 0)
m.c2025 = Constraint(expr= m.x1121 - m.b1691 <= 0)
m.c2026 = Constraint(expr= m.x1122 - m.b1692 <= 0)
m.c2027 = Constraint(expr= m.x1123 - m.b1693 <= 0)
m.c2028 = Constraint(expr= m.x1124 - m.b1754 <= 0)
m.c2029 = Constraint(expr= m.x1125 - m.b1755 <= 0)
m.c2030 = Constraint(expr= m.x1126 - m.b1756 <= 0)
m.c2031 = Constraint(expr= m.x1127 - m.b1757 <= 0)
m.c2032 = Constraint(expr= m.x1128 - m.b1758 <= 0)
m.c2033 = Constraint(expr= m.x1129 - m.b1759 <= 0)
m.c2034 = Constraint(expr= m.x1130 - m.b1538 <= 0)
m.c2035 = Constraint(expr= m.x1136 - m.b1688 <= 0)
m.c2036 = Constraint(expr= m.x1137 - m.b1689 <= 0)
m.c2037 = Constraint(expr= m.x1138 - m.b1690 <= 0)
m.c2038 = Constraint(expr= m.x1139 - m.b1691 <= 0)
m.c2039 = Constraint(expr= m.x1140 - m.b1692 <= 0)
m.c2040 = Constraint(expr= m.x1141 - m.b1693 <= 0)
m.c2041 = Constraint(expr= m.x1142 - m.b1754 <= 0)
m.c2042 = Constraint(expr= m.x1143 - m.b1755 <= 0)
m.c2043 = Constraint(expr= m.x1144 - m.b1756 <= 0)
m.c2044 = Constraint(expr= m.x1145 - m.b1757 <= 0)
m.c2045 = Constraint(expr= m.x1146 - m.b1758 <= 0)
m.c2046 = Constraint(expr= m.x1147 - m.b1759 <= 0)
m.c2047 = Constraint(expr= m.x1148 - m.b1760 <= 0)
m.c2048 = Constraint(expr= m.x1149 - m.b1761 <= 0)
m.c2049 = Constraint(expr= m.x1150 - m.b1762 <= 0)
m.c2050 = Constraint(expr= m.x1151 - m.b1763 <= 0)
m.c2051 = Constraint(expr= m.x1152 - m.b1764 <= 0)
m.c2052 = Constraint(expr= m.x1153 - m.b1765 <= 0)
m.c2053 = Constraint(expr= m.x1154 - m.b1538 <= 0)
m.c2054 = Constraint(expr= m.x1160 - m.b1688 <= 0)
m.c2055 = Constraint(expr= m.x1161 - m.b1689 <= 0)
m.c2056 = Constraint(expr= m.x1162 - m.b1690 <= 0)
m.c2057 = Constraint(expr= m.x1163 - m.b1691 <= 0)
m.c2058 = Constraint(expr= m.x1164 - m.b1692 <= 0)
m.c2059 = Constraint(expr= m.x1165 - m.b1693 <= 0)
m.c2060 = Constraint(expr= m.x1166 - m.b1754 <= 0)
m.c2061 = Constraint(expr= m.x1167 - m.b1755 <= 0)
m.c2062 = Constraint(expr= m.x1168 - m.b1756 <= 0)
m.c2063 = Constraint(expr= m.x1169 - m.b1757 <= 0)
m.c2064 = Constraint(expr= m.x1170 - m.b1758 <= 0)
m.c2065 = Constraint(expr= m.x1171 - m.b1759 <= 0)
m.c2066 = Constraint(expr= m.x1172 - m.b1760 <= 0)
m.c2067 = Constraint(expr= m.x1173 - m.b1761 <= 0)
m.c2068 = Constraint(expr= m.x1174 - m.b1762 <= 0)
m.c2069 = Constraint(expr= m.x1175 - m.b1763 <= 0)
m.c2070 = Constraint(expr= m.x1176 - m.b1764 <= 0)
m.c2071 = Constraint(expr= m.x1177 - m.b1765 <= 0)
m.c2072 = Constraint(expr= m.x1178 - m.b1766 <= 0)
m.c2073 = Constraint(expr= m.x1179 - m.b1767 <= 0)
m.c2074 = Constraint(expr= m.x1180 - m.b1768 <= 0)
m.c2075 = Constraint(expr= m.x1181 - m.b1769 <= 0)
m.c2076 = Constraint(expr= m.x1182 - m.b1770 <= 0)
m.c2077 = Constraint(expr= m.x1183 - m.b1771 <= 0)
m.c2078 = Constraint(expr= m.x1184 - m.b1538 <= 0)
m.c2079 = Constraint(expr= m.x1190 - m.b1688 <= 0)
m.c2080 = Constraint(expr= m.x1191 - m.b1689 <= 0)
m.c2081 = Constraint(expr= m.x1192 - m.b1690 <= 0)
m.c2082 = Constraint(expr= m.x1193 - m.b1691 <= 0)
m.c2083 = Constraint(expr= m.x1194 - m.b1692 <= 0)
m.c2084 = Constraint(expr= m.x1195 - m.b1693 <= 0)
m.c2085 = Constraint(expr= m.x1196 - m.b1754 <= 0)
m.c2086 = Constraint(expr= m.x1197 - m.b1755 <= 0)
m.c2087 = Constraint(expr= m.x1198 - m.b1756 <= 0)
m.c2088 = Constraint(expr= m.x1199 - m.b1757 <= 0)
m.c2089 = Constraint(expr= m.x1200 - m.b1758 <= 0)
m.c2090 = Constraint(expr= m.x1201 - m.b1759 <= 0)
m.c2091 = Constraint(expr= m.x1202 - m.b1760 <= 0)
m.c2092 = Constraint(expr= m.x1203 - m.b1761 <= 0)
m.c2093 = Constraint(expr= m.x1204 - m.b1762 <= 0)
m.c2094 = Constraint(expr= m.x1205 - m.b1763 <= 0)
m.c2095 = Constraint(expr= m.x1206 - m.b1764 <= 0)
m.c2096 = Constraint(expr= m.x1207 - m.b1765 <= 0)
m.c2097 = Constraint(expr= m.x1208 - m.b1766 <= 0)
m.c2098 = Constraint(expr= m.x1209 - m.b1767 <= 0)
m.c2099 = Constraint(expr= m.x1210 - m.b1768 <= 0)
m.c2100 = Constraint(expr= m.x1211 - m.b1769 <= 0)
m.c2101 = Constraint(expr= m.x1212 - m.b1770 <= 0)
m.c2102 = Constraint(expr= m.x1213 - m.b1771 <= 0)
m.c2103 = Constraint(expr= m.x1214 - m.b1772 <= 0)
m.c2104 = Constraint(expr= m.x1215 - m.b1773 <= 0)
m.c2105 = Constraint(expr= m.x1216 - m.b1774 <= 0)
m.c2106 = Constraint(expr= m.x1217 - m.b1775 <= 0)
m.c2107 = Constraint(expr= m.x1218 - m.b1776 <= 0)
m.c2108 = Constraint(expr= m.x1219 - m.b1777 <= 0)
m.c2109 = Constraint(expr= m.x1220 - m.b1538 <= 0)
m.c2110 = Constraint(expr= m.x1226 - m.b1556 <= 0)
m.c2111 = Constraint(expr= m.x1227 - m.b1557 <= 0)
m.c2112 = Constraint(expr= m.x1228 - m.b1558 <= 0)
m.c2113 = Constraint(expr= m.x1229 - m.b1559 <= 0)
m.c2114 = Constraint(expr= m.x1232 - m.b1538 <= 0)
m.c2115 = Constraint(expr= m.x1238 - m.b1556 <= 0)
m.c2116 = Constraint(expr= m.x1239 - m.b1557 <= 0)
m.c2117 = Constraint(expr= m.x1240 - m.b1558 <= 0)
m.c2118 = Constraint(expr= m.x1241 - m.b1559 <= 0)
m.c2119 = Constraint(expr= m.x1244 - m.b1568 <= 0)
m.c2120 = Constraint(expr= m.x1245 - m.b1569 <= 0)
m.c2121 = Constraint(expr= m.x1246 - m.b1570 <= 0)
m.c2122 = Constraint(expr= m.x1247 - m.b1571 <= 0)
m.c2123 = Constraint(expr= m.x1248 - m.b1572 <= 0)
m.c2124 = Constraint(expr= m.x1249 - m.b1573 <= 0)
m.c2125 = Constraint(expr= m.x1250 - m.b1844 <= 0)
m.c2126 = Constraint(expr= m.x1251 - m.b1845 <= 0)
m.c2127 = Constraint(expr= m.x1252 - m.b1846 <= 0)
m.c2128 = Constraint(expr= m.x1253 - m.b1847 <= 0)
m.c2129 = Constraint(expr= m.x1254 - m.b1848 <= 0)
m.c2130 = Constraint(expr= m.x1255 - m.b1849 <= 0)
m.c2131 = Constraint(expr= m.x1256 - m.b1610 <= 0)
m.c2132 = Constraint(expr= m.x1257 - m.b1611 <= 0)
m.c2133 = Constraint(expr= m.x1258 - m.b1612 <= 0)
m.c2134 = Constraint(expr= m.x1259 - m.b1613 <= 0)
m.c2135 = Constraint(expr= m.x1260 - m.b1614 <= 0)
m.c2136 = Constraint(expr= m.x1261 - m.b1615 <= 0)
m.c2137 = Constraint(expr= m.x1262 - m.b1730 <= 0)
m.c2138 = Constraint(expr= m.x1263 - m.b1731 <= 0)
m.c2139 = Constraint(expr= m.x1264 - m.b1732 <= 0)
m.c2140 = Constraint(expr= m.x1265 - m.b1733 <= 0)
m.c2141 = Constraint(expr= m.x1266 - m.b1734 <= 0)
m.c2142 = Constraint(expr= m.x1267 - m.b1735 <= 0)
m.c2143 = Constraint(expr= m.x1268 - m.b1736 <= 0)
m.c2144 = Constraint(expr= m.x1269 - m.b1737 <= 0)
m.c2145 = Constraint(expr= m.x1270 - m.b1738 <= 0)
m.c2146 = Constraint(expr= m.x1271 - m.b1739 <= 0)
m.c2147 = Constraint(expr= m.x1272 - m.b1740 <= 0)
m.c2148 = Constraint(expr= m.x1273 - m.b1741 <= 0)
m.c2149 = Constraint(expr= m.x1274 - m.b1640 <= 0)
m.c2150 = Constraint(expr= m.x1275 - m.b1641 <= 0)
m.c2151 = Constraint(expr= m.x1276 - m.b1642 <= 0)
m.c2152 = Constraint(expr= m.x1277 - m.b1643 <= 0)
m.c2153 = Constraint(expr= m.x1278 - m.b1644 <= 0)
m.c2154 = Constraint(expr= m.x1279 - m.b1645 <= 0)
m.c2155 = Constraint(expr= m.x1280 - m.b1640 <= 0)
m.c2156 = Constraint(expr= m.x1281 - m.b1641 <= 0)
m.c2157 = Constraint(expr= m.x1282 - m.b1642 <= 0)
m.c2158 = Constraint(expr= m.x1283 - m.b1643 <= 0)
m.c2159 = Constraint(expr= m.x1284 - m.b1644 <= 0)
m.c2160 = Constraint(expr= m.x1285 - m.b1645 <= 0)
m.c2161 = Constraint(expr= m.x1286 - m.b1802 <= 0)
m.c2162 = Constraint(expr= m.x1287 - m.b1803 <= 0)
m.c2163 = Constraint(expr= m.x1288 - m.b1804 <= 0)
m.c2164 = Constraint(expr= m.x1289 - m.b1805 <= 0)
m.c2165 = Constraint(expr= m.x1290 - m.b1806 <= 0)
m.c2166 = Constraint(expr= m.x1291 - m.b1807 <= 0)
m.c2167 = Constraint(expr= m.x1292 - m.b1562 <= 0)
m.c2168 = Constraint(expr= m.x1293 - m.b1563 <= 0)
m.c2169 = Constraint(expr= m.x1294 - m.b1564 <= 0)
m.c2170 = Constraint(expr= m.x1295 - m.b1565 <= 0)
m.c2171 = Constraint(expr= m.x1296 - m.b1566 <= 0)
m.c2172 = Constraint(expr= m.x1298 - m.b1562 <= 0)
m.c2173 = Constraint(expr= m.x1299 - m.b1563 <= 0)
m.c2174 = Constraint(expr= m.x1300 - m.b1564 <= 0)
m.c2175 = Constraint(expr= m.x1301 - m.b1565 <= 0)
m.c2176 = Constraint(expr= m.x1302 - m.b1566 <= 0)
m.c2177 = Constraint(expr= m.x1304 - m.b1604 <= 0)
m.c2178 = Constraint(expr= m.x1305 - m.b1605 <= 0)
m.c2179 = Constraint(expr= m.x1306 - m.b1606 <= 0)
m.c2180 = Constraint(expr= m.x1307 - m.b1607 <= 0)
m.c2181 = Constraint(expr= m.x1308 - m.b1608 <= 0)
m.c2182 = Constraint(expr= m.x1309 - m.b1609 <= 0)
m.c2183 = Constraint(expr= m.x1310 - m.b1616 <= 0)
m.c2184 = Constraint(expr= m.x1311 - m.b1617 <= 0)
m.c2185 = Constraint(expr= m.x1312 - m.b1618 <= 0)
m.c2186 = Constraint(expr= m.x1313 - m.b1619 <= 0)
m.c2187 = Constraint(expr= m.x1314 - m.b1620 <= 0)
m.c2188 = Constraint(expr= m.x1315 - m.b1621 <= 0)
m.c2189 = Constraint(expr= m.x1316 - m.b1538 <= 0)
m.c2190 = Constraint(expr= m.x1322 - m.b1556 <= 0)
m.c2191 = Constraint(expr= m.x1323 - m.b1557 <= 0)
m.c2192 = Constraint(expr= m.x1324 - m.b1558 <= 0)
m.c2193 = Constraint(expr= m.x1325 - m.b1559 <= 0)
m.c2194 = Constraint(expr= m.x1328 - m.b1610 <= 0)
m.c2195 = Constraint(expr= m.x1329 - m.b1611 <= 0)
m.c2196 = Constraint(expr= m.x1330 - m.b1612 <= 0)
m.c2197 = Constraint(expr= m.x1331 - m.b1613 <= 0)
m.c2198 = Constraint(expr= m.x1332 - m.b1614 <= 0)
m.c2199 = Constraint(expr= m.x1333 - m.b1615 <= 0)
m.c2200 = Constraint(expr= m.x1334 - m.b1538 <= 0)
m.c2201 = Constraint(expr= m.x1340 - m.b1556 <= 0)
m.c2202 = Constraint(expr= m.x1341 - m.b1557 <= 0)
m.c2203 = Constraint(expr= m.x1342 - m.b1558 <= 0)
m.c2204 = Constraint(expr= m.x1343 - m.b1559 <= 0)
m.c2205 = Constraint(expr= m.x1346 - m.b1610 <= 0)
m.c2206 = Constraint(expr= m.x1347 - m.b1611 <= 0)
m.c2207 = Constraint(expr= m.x1348 - m.b1612 <= 0)
m.c2208 = Constraint(expr= m.x1349 - m.b1613 <= 0)
m.c2209 = Constraint(expr= m.x1350 - m.b1614 <= 0)
m.c2210 = Constraint(expr= m.x1351 - m.b1615 <= 0)
m.c2211 = Constraint(expr= m.x1352 - m.b1538 <= 0)
m.c2212 = Constraint(expr= m.x1358 - m.b1568 <= 0)
m.c2213 = Constraint(expr= m.x1359 - m.b1569 <= 0)
m.c2214 = Constraint(expr= m.x1360 - m.b1570 <= 0)
m.c2215 = Constraint(expr= m.x1361 - m.b1571 <= 0)
m.c2216 = Constraint(expr= m.x1362 - m.b1572 <= 0)
m.c2217 = Constraint(expr= m.x1363 - m.b1573 <= 0)
m.c2218 = Constraint(expr= m.x1364 - m.b1538 <= 0)
m.c2219 = Constraint(expr= m.x1370 - m.b1556 <= 0)
m.c2220 = Constraint(expr= m.x1371 - m.b1557 <= 0)
m.c2221 = Constraint(expr= m.x1372 - m.b1558 <= 0)
m.c2222 = Constraint(expr= m.x1373 - m.b1559 <= 0)
m.c2223 = Constraint(expr= m.x1376 - m.b1538 <= 0)
m.c2224 = Constraint(expr= m.x1382 - m.b1784 <= 0)
m.c2225 = Constraint(expr= m.x1383 - m.b1785 <= 0)
m.c2226 = Constraint(expr= m.x1384 - m.b1786 <= 0)
m.c2227 = Constraint(expr= m.x1385 - m.b1787 <= 0)
m.c2228 = Constraint(expr= m.x1386 - m.b1788 <= 0)
m.c2229 = Constraint(expr= m.x1387 - m.b1789 <= 0)
m.c2230 = Constraint(expr= m.x1388 - m.b1982 <= 0)
m.c2231 = Constraint(expr= m.x1389 - m.b1983 <= 0)
m.c2232 = Constraint(expr= m.x1390 - m.b1984 <= 0)
m.c2233 = Constraint(expr= m.x1391 - m.b1985 <= 0)
m.c2234 = Constraint(expr= m.x1392 - m.b1986 <= 0)
m.c2235 = Constraint(expr= m.x1393 - m.b1987 <= 0)
m.c2236 = Constraint(expr= m.x1394 - m.b1604 <= 0)
m.c2237 = Constraint(expr= m.x1395 - m.b1605 <= 0)
m.c2238 = Constraint(expr= m.x1396 - m.b1606 <= 0)
m.c2239 = Constraint(expr= m.x1397 - m.b1607 <= 0)
m.c2240 = Constraint(expr= m.x1398 - m.b1608 <= 0)
m.c2241 = Constraint(expr= m.x1399 - m.b1609 <= 0)
m.c2242 = Constraint(expr= m.x1400 - m.b1730 <= 0)
m.c2243 = Constraint(expr= m.x1401 - m.b1731 <= 0)
m.c2244 = Constraint(expr= m.x1402 - m.b1732 <= 0)
m.c2245 = Constraint(expr= m.x1403 - m.b1733 <= 0)
m.c2246 = Constraint(expr= m.x1404 - m.b1734 <= 0)
m.c2247 = Constraint(expr= m.x1405 - m.b1735 <= 0)
m.c2248 = Constraint(expr= m.x1406 - m.b1736 <= 0)
m.c2249 = Constraint(expr= m.x1407 - m.b1737 <= 0)
m.c2250 = Constraint(expr= m.x1408 - m.b1738 <= 0)
m.c2251 = Constraint(expr= m.x1409 - m.b1739 <= 0)
m.c2252 = Constraint(expr= m.x1410 - m.b1740 <= 0)
m.c2253 = Constraint(expr= m.x1411 - m.b1741 <= 0)
m.c2254 = Constraint(expr= m.x1412 - m.b1814 <= 0)
m.c2255 = Constraint(expr= m.x1413 - m.b1815 <= 0)
m.c2256 = Constraint(expr= m.x1414 - m.b1816 <= 0)
m.c2257 = Constraint(expr= m.x1415 - m.b1817 <= 0)
m.c2258 = Constraint(expr= m.x1416 - m.b1818 <= 0)
m.c2259 = Constraint(expr= m.x1417 - m.b1819 <= 0)
m.c2260 = Constraint(expr= m.x1418 - m.b1550 <= 0)
m.c2261 = Constraint(expr= m.x1419 - m.b1551 <= 0)
m.c2262 = Constraint(expr= m.x1420 - m.b1552 <= 0)
m.c2263 = Constraint(expr= m.x1424 - m.b1730 <= 0)
m.c2264 = Constraint(expr= m.x1425 - m.b1731 <= 0)
m.c2265 = Constraint(expr= m.x1426 - m.b1732 <= 0)
m.c2266 = Constraint(expr= m.x1427 - m.b1733 <= 0)
m.c2267 = Constraint(expr= m.x1428 - m.b1734 <= 0)
m.c2268 = Constraint(expr= m.x1429 - m.b1735 <= 0)
m.c2269 = Constraint(expr= m.x1430 - m.b1544 <= 0)
m.c2270 = Constraint(expr= m.x1431 - m.b1545 <= 0)
m.c2271 = Constraint(expr= m.x1436 - m.b1544 <= 0)
m.c2272 = Constraint(expr= m.x1437 - m.b1545 <= 0)
m.c2273 = Constraint(expr= m.x1442 - m.b1886 <= 0)
m.c2274 = Constraint(expr= m.x1443 - m.b1887 <= 0)
m.c2275 = Constraint(expr= m.x1444 - m.b1888 <= 0)
m.c2276 = Constraint(expr= m.x1445 - m.b1889 <= 0)
m.c2277 = Constraint(expr= m.x1446 - m.b1890 <= 0)
m.c2278 = Constraint(expr= m.x1447 - m.b1891 <= 0)
m.c2279 = Constraint(expr= m.x1448 - m.b1640 <= 0)
m.c2280 = Constraint(expr= m.x1449 - m.b1641 <= 0)
m.c2281 = Constraint(expr= m.x1450 - m.b1642 <= 0)
m.c2282 = Constraint(expr= m.x1451 - m.b1643 <= 0)
m.c2283 = Constraint(expr= m.x1452 - m.b1644 <= 0)
m.c2284 = Constraint(expr= m.x1453 - m.b1645 <= 0)
m.c2285 = Constraint(expr= m.x1454 - m.b1640 <= 0)
m.c2286 = Constraint(expr= m.x1455 - m.b1641 <= 0)
m.c2287 = Constraint(expr= m.x1456 - m.b1642 <= 0)
m.c2288 = Constraint(expr= m.x1457 - m.b1643 <= 0)
m.c2289 = Constraint(expr= m.x1458 - m.b1644 <= 0)
m.c2290 = Constraint(expr= m.x1459 - m.b1645 <= 0)
m.c2291 = Constraint(expr= m.x1460 - m.b1640 <= 0)
m.c2292 = Constraint(expr= m.x1461 - m.b1641 <= 0)
m.c2293 = Constraint(expr= m.x1462 - m.b1642 <= 0)
m.c2294 = Constraint(expr= m.x1463 - m.b1643 <= 0)
m.c2295 = Constraint(expr= m.x1464 - m.b1644 <= 0)
m.c2296 = Constraint(expr= m.x1465 - m.b1645 <= 0)
m.c2297 = Constraint(expr= m.x1466 - m.b1640 <= 0)
m.c2298 = Constraint(expr= m.x1467 - m.b1641 <= 0)
m.c2299 = Constraint(expr= m.x1468 - m.b1642 <= 0)
m.c2300 = Constraint(expr= m.x1469 - m.b1643 <= 0)
m.c2301 = Constraint(expr= m.x1470 - m.b1644 <= 0)
m.c2302 = Constraint(expr= m.x1471 - m.b1645 <= 0)
m.c2303 = Constraint(expr= m.x1472 - m.b1640 <= 0)
m.c2304 = Constraint(expr= m.x1473 - m.b1641 <= 0)
m.c2305 = Constraint(expr= m.x1474 - m.b1642 <= 0)
m.c2306 = Constraint(expr= m.x1475 - m.b1643 <= 0)
m.c2307 = Constraint(expr= m.x1476 - m.b1644 <= 0)
m.c2308 = Constraint(expr= m.x1477 - m.b1645 <= 0)
m.c2309 = Constraint(expr= m.x1478 - m.b1640 <= 0)
m.c2310 = Constraint(expr= m.x1479 - m.b1641 <= 0)
m.c2311 = Constraint(expr= m.x1480 - m.b1642 <= 0)
m.c2312 = Constraint(expr= m.x1481 - m.b1643 <= 0)
m.c2313 = Constraint(expr= m.x1482 - m.b1644 <= 0)
m.c2314 = Constraint(expr= m.x1483 - m.b1645 <= 0)
m.c2315 = Constraint(expr= m.x1484 - m.b1640 <= 0)
m.c2316 = Constraint(expr= m.x1485 - m.b1641 <= 0)
m.c2317 = Constraint(expr= m.x1486 - m.b1642 <= 0)
m.c2318 = Constraint(expr= m.x1487 - m.b1643 <= 0)
m.c2319 = Constraint(expr= m.x1488 - m.b1644 <= 0)
m.c2320 = Constraint(expr= m.x1489 - m.b1645 <= 0)
m.c2321 = Constraint(expr= m.x1490 - m.b1538 <= 0)
m.c2322 = Constraint(expr= m.x1496 - m.b1538 <= 0)
m.c2323 = Constraint(expr= m.x1502 - m.b1538 <= 0)
m.c2324 = Constraint(expr= m.x1508 - m.b1538 <= 0)
m.c2325 = Constraint(expr= m.x1514 - m.b1562 <= 0)
m.c2326 = Constraint(expr= m.x1515 - m.b1563 <= 0)
m.c2327 = Constraint(expr= m.x1516 - m.b1564 <= 0)
m.c2328 = Constraint(expr= m.x1517 - m.b1565 <= 0)
m.c2329 = Constraint(expr= m.x1518 - m.b1566 <= 0)
m.c2330 = Constraint(expr= m.x1520 - m.b1784 <= 0)
m.c2331 = Constraint(expr= m.x1521 - m.b1785 <= 0)
m.c2332 = Constraint(expr= m.x1522 - m.b1786 <= 0)
m.c2333 = Constraint(expr= m.x1523 - m.b1787 <= 0)
m.c2334 = Constraint(expr= m.x1524 - m.b1788 <= 0)
m.c2335 = Constraint(expr= m.x1525 - m.b1789 <= 0)
m.c2336 = Constraint(expr= m.x1526 - m.b1736 <= 0)
m.c2337 = Constraint(expr= m.x1527 - m.b1737 <= 0)
m.c2338 = Constraint(expr= m.x1528 - m.b1738 <= 0)
m.c2339 = Constraint(expr= m.x1529 - m.b1739 <= 0)
m.c2340 = Constraint(expr= m.x1530 - m.b1740 <= 0)
m.c2341 = Constraint(expr= m.x1531 - m.b1741 <= 0)
m.c2342 = Constraint(expr= m.x1532 - m.b1622 <= 0)
m.c2343 = Constraint(expr= m.x1533 - m.b1623 <= 0)
m.c2344 = Constraint(expr= m.x1534 - m.b1624 <= 0)
m.c2345 = Constraint(expr= m.x1535 - m.b1625 <= 0)
m.c2346 = Constraint(expr= m.x1536 - m.b1626 <= 0)
m.c2347 = Constraint(expr= m.x1537 - m.b1627 <= 0)
m.c2348 = Constraint(expr= m.x15 == 0)
m.c2349 = Constraint(expr= m.x16 == 0)
m.c2350 = Constraint(expr= m.x17 == 0)
m.c2351 = Constraint(expr= m.x18 == 0)
m.c2352 = Constraint(expr= m.x19 == 0)
m.c2353 = Constraint(expr= m.x21 == 0)
m.c2354 = Constraint(expr= m.x22 == 0)
m.c2355 = Constraint(expr= m.x23 == 0)
m.c2356 = Constraint(expr= m.x24 == 0)
m.c2357 = Constraint(expr= m.x25 == 0)
m.c2358 = Constraint(expr= m.x27 == 0)
m.c2359 = Constraint(expr= m.x28 == 0)
m.c2360 = Constraint(expr= m.x29 == 0)
m.c2361 = Constraint(expr= m.x30 == 0)
m.c2362 = Constraint(expr= m.x31 == 0)
m.c2363 = Constraint(expr= m.x33 == 0)
m.c2364 = Constraint(expr= m.x34 == 0)
m.c2365 = Constraint(expr= m.x35 == 0)
m.c2366 = Constraint(expr= m.x36 == 0)
m.c2367 = Constraint(expr= m.x37 == 0)
m.c2368 = Constraint(expr= m.x39 == 0)
m.c2369 = Constraint(expr= m.x40 == 0)
m.c2370 = Constraint(expr= m.x41 == 0)
m.c2371 = Constraint(expr= m.x42 == 0)
m.c2372 = Constraint(expr= m.x43 == 0)
m.c2373 = Constraint(expr= m.x46 == 0)
m.c2374 = Constraint(expr= m.x47 == 0)
m.c2375 = Constraint(expr= m.x48 == 0)
m.c2376 = Constraint(expr= m.x49 == 0)
m.c2377 = Constraint(expr= m.x52 == 0)
m.c2378 = Constraint(expr= m.x53 == 0)
m.c2379 = Constraint(expr= m.x54 == 0)
m.c2380 = Constraint(expr= m.x55 == 0)
m.c2381 = Constraint(expr= m.x58 == 0)
m.c2382 = Constraint(expr= m.x59 == 0)
m.c2383 = Constraint(expr= m.x60 == 0)
m.c2384 = Constraint(expr= m.x61 == 0)
m.c2385 = Constraint(expr= m.x63 == 0)
m.c2386 = Constraint(expr= m.x64 == 0)
m.c2387 = Constraint(expr= m.x65 == 0)
m.c2388 = Constraint(expr= m.x66 == 0)
m.c2389 = Constraint(expr= m.x67 == 0)
m.c2390 = Constraint(expr= m.x70 == 0)
m.c2391 = Constraint(expr= m.x71 == 0)
m.c2392 = Constraint(expr= m.x72 == 0)
m.c2393 = Constraint(expr= m.x73 == 0)
m.c2394 = Constraint(expr= m.x77 == 0)
m.c2395 = Constraint(expr= m.x78 == 0)
m.c2396 = Constraint(expr= m.x79 == 0)
m.c2397 = Constraint(expr= m.x83 == 0)
m.c2398 = Constraint(expr= m.x84 == 0)
m.c2399 = Constraint(expr= m.x85 == 0)
m.c2400 = Constraint(expr= m.x89 == 0)
m.c2401 = Constraint(expr= m.x90 == 0)
m.c2402 = Constraint(expr= m.x91 == 0)
m.c2403 = Constraint(expr= m.x95 == 0)
m.c2404 = Constraint(expr= m.x96 == 0)
m.c2405 = Constraint(expr= m.x97 == 0)
m.c2406 = Constraint(expr= m.x101 == 0)
m.c2407 = Constraint(expr= m.x102 == 0)
m.c2408 = Constraint(expr= m.x103 == 0)
m.c2409 = Constraint(expr= m.x107 == 0)
m.c2410 = Constraint(expr= m.x108 == 0)
m.c2411 = Constraint(expr= m.x109 == 0)
m.c2412 = Constraint(expr= m.x113 == 0)
m.c2413 = Constraint(expr= m.x114 == 0)
m.c2414 = Constraint(expr= m.x115 == 0)
m.c2415 = Constraint(expr= m.x119 == 0)
m.c2416 = Constraint(expr= m.x120 == 0)
m.c2417 = Constraint(expr= m.x121 == 0)
m.c2418 = Constraint(expr= m.x123 == 0)
m.c2419 = Constraint(expr= m.x124 == 0)
m.c2420 = Constraint(expr= m.x125 == 0)
m.c2421 = Constraint(expr= m.x126 == 0)
m.c2422 = Constraint(expr= m.x127 == 0)
m.c2423 = Constraint(expr= m.x132 == 0)
m.c2424 = Constraint(expr= m.x133 == 0)
m.c2425 = Constraint(expr= m.x138 == 0)
m.c2426 = Constraint(expr= m.x139 == 0)
m.c2427 = Constraint(expr= m.x144 == 0)
m.c2428 = Constraint(expr= m.x145 == 0)
m.c2429 = Constraint(expr= m.x150 == 0)
m.c2430 = Constraint(expr= m.x151 == 0)
m.c2431 = Constraint(expr= m.x153 == 0)
m.c2432 = Constraint(expr= m.x154 == 0)
m.c2433 = Constraint(expr= m.x155 == 0)
m.c2434 = Constraint(expr= m.x156 == 0)
m.c2435 = Constraint(expr= m.x157 == 0)
m.c2436 = Constraint(expr= m.x163 == 0)
m.c2437 = Constraint(expr= m.x169 == 0)
m.c2438 = Constraint(expr= m.x171 == 0)
m.c2439 = Constraint(expr= m.x172 == 0)
m.c2440 = Constraint(expr= m.x173 == 0)
m.c2441 = Constraint(expr= m.x174 == 0)
m.c2442 = Constraint(expr= m.x175 == 0)
m.c2443 = Constraint(expr= m.x225 == 0)
m.c2444 = Constraint(expr= m.x226 == 0)
m.c2445 = Constraint(expr= m.x227 == 0)
m.c2446 = Constraint(expr= m.x228 == 0)
m.c2447 = Constraint(expr= m.x229 == 0)
m.c2448 = Constraint(expr= m.x232 == 0)
m.c2449 = Constraint(expr= m.x233 == 0)
m.c2450 = Constraint(expr= m.x234 == 0)
m.c2451 = Constraint(expr= m.x235 == 0)
m.c2452 = Constraint(expr= m.x239 == 0)
m.c2453 = Constraint(expr= m.x240 == 0)
m.c2454 = Constraint(expr= m.x241 == 0)
m.c2455 = Constraint(expr= m.x246 == 0)
m.c2456 = Constraint(expr= m.x247 == 0)
m.c2457 = Constraint(expr= m.x256 == 0)
m.c2458 = Constraint(expr= m.x257 == 0)
m.c2459 = Constraint(expr= m.x258 == 0)
m.c2460 = Constraint(expr= m.x259 == 0)
m.c2461 = Constraint(expr= m.x263 == 0)
m.c2462 = Constraint(expr= m.x264 == 0)
m.c2463 = Constraint(expr= m.x265 == 0)
m.c2464 = Constraint(expr= m.x303 == 0)
m.c2465 = Constraint(expr= m.x304 == 0)
m.c2466 = Constraint(expr= m.x305 == 0)
m.c2467 = Constraint(expr= m.x306 == 0)
m.c2468 = Constraint(expr= m.x307 == 0)
m.c2469 = Constraint(expr= m.x310 == 0)
m.c2470 = Constraint(expr= m.x311 == 0)
m.c2471 = Constraint(expr= m.x312 == 0)
m.c2472 = Constraint(expr= m.x313 == 0)
m.c2473 = Constraint(expr= m.x317 == 0)
m.c2474 = Constraint(expr= m.x318 == 0)
m.c2475 = Constraint(expr= m.x319 == 0)
m.c2476 = Constraint(expr= m.x364 == 0)
m.c2477 = Constraint(expr= m.x365 == 0)
m.c2478 = Constraint(expr= m.x366 == 0)
m.c2479 = Constraint(expr= m.x367 == 0)
m.c2480 = Constraint(expr= m.x371 == 0)
m.c2481 = Constraint(expr= m.x372 == 0)
m.c2482 = Constraint(expr= m.x373 == 0)
m.c2483 = Constraint(expr= m.x412 == 0)
m.c2484 = Constraint(expr= m.x413 == 0)
m.c2485 = Constraint(expr= m.x414 == 0)
m.c2486 = Constraint(expr= m.x415 == 0)
m.c2487 = Constraint(expr= m.x419 == 0)
m.c2488 = Constraint(expr= m.x420 == 0)
m.c2489 = Constraint(expr= m.x421 == 0)
m.c2490 = Constraint(expr= m.x471 == 0)
m.c2491 = Constraint(expr= m.x472 == 0)
m.c2492 = Constraint(expr= m.x473 == 0)
m.c2493 = Constraint(expr= m.x474 == 0)
m.c2494 = Constraint(expr= m.x475 == 0)
m.c2495 = Constraint(expr= m.x483 == 0)
m.c2496 = Constraint(expr= m.x484 == 0)
m.c2497 = Constraint(expr= m.x485 == 0)
m.c2498 = Constraint(expr= m.x486 == 0)
m.c2499 = Constraint(expr= m.x487 == 0)
m.c2500 = Constraint(expr= m.x493 == 0)
m.c2501 = Constraint(expr= m.x511 == 0)
m.c2502 = Constraint(expr= m.x520 == 0)
m.c2503 = Constraint(expr= m.x521 == 0)
m.c2504 = Constraint(expr= m.x522 == 0)
m.c2505 = Constraint(expr= m.x523 == 0)
m.c2506 = Constraint(expr= m.x527 == 0)
m.c2507 = Constraint(expr= m.x528 == 0)
m.c2508 = Constraint(expr= m.x529 == 0)
m.c2509 = Constraint(expr= m.x538 == 0)
m.c2510 = Constraint(expr= m.x539 == 0)
m.c2511 = Constraint(expr= m.x540 == 0)
m.c2512 = Constraint(expr= m.x541 == 0)
m.c2513 = Constraint(expr= m.x545 == 0)
m.c2514 = Constraint(expr= m.x546 == 0)
m.c2515 = Constraint(expr= m.x547 == 0)
m.c2516 = Constraint(expr= m.x562 == 0)
m.c2517 = Constraint(expr= m.x563 == 0)
m.c2518 = Constraint(expr= m.x564 == 0)
m.c2519 = Constraint(expr= m.x565 == 0)
m.c2520 = Constraint(expr= m.x569 == 0)
m.c2521 = Constraint(expr= m.x570 == 0)
m.c2522 = Constraint(expr= m.x571 == 0)
m.c2523 = Constraint(expr= m.x598 == 0)
m.c2524 = Constraint(expr= m.x599 == 0)
m.c2525 = Constraint(expr= m.x600 == 0)
m.c2526 = Constraint(expr= m.x601 == 0)
m.c2527 = Constraint(expr= m.x651 == 0)
m.c2528 = Constraint(expr= m.x652 == 0)
m.c2529 = Constraint(expr= m.x653 == 0)
m.c2530 = Constraint(expr= m.x654 == 0)
m.c2531 = Constraint(expr= m.x655 == 0)
m.c2532 = Constraint(expr= m.x658 == 0)
m.c2533 = Constraint(expr= m.x659 == 0)
m.c2534 = Constraint(expr= m.x660 == 0)
m.c2535 = Constraint(expr= m.x661 == 0)
m.c2536 = Constraint(expr= m.x666 == 0)
m.c2537 = Constraint(expr= m.x667 == 0)
m.c2538 = Constraint(expr= m.x673 == 0)
m.c2539 = Constraint(expr= m.x687 == 0)
m.c2540 = Constraint(expr= m.x688 == 0)
m.c2541 = Constraint(expr= m.x689 == 0)
m.c2542 = Constraint(expr= m.x690 == 0)
m.c2543 = Constraint(expr= m.x691 == 0)
m.c2544 = Constraint(expr= m.x694 == 0)
m.c2545 = Constraint(expr= m.x695 == 0)
m.c2546 = Constraint(expr= m.x696 == 0)
m.c2547 = Constraint(expr= m.x697 == 0)
m.c2548 = Constraint(expr= m.x702 == 0)
m.c2549 = Constraint(expr= m.x703 == 0)
m.c2550 = Constraint(expr= m.x709 == 0)
m.c2551 = Constraint(expr= m.x729 == 0)
m.c2552 = Constraint(expr= m.x730 == 0)
m.c2553 = Constraint(expr= m.x731 == 0)
m.c2554 = Constraint(expr= m.x732 == 0)
m.c2555 = Constraint(expr= m.x733 == 0)
m.c2556 = Constraint(expr= m.x738 == 0)
m.c2557 = Constraint(expr= m.x739 == 0)
m.c2558 = Constraint(expr= m.x745 == 0)
m.c2559 = Constraint(expr= m.x778 == 0)
m.c2560 = Constraint(expr= m.x779 == 0)
m.c2561 = Constraint(expr= m.x780 == 0)
m.c2562 = Constraint(expr= m.x781 == 0)
m.c2563 = Constraint(expr= m.x795 == 0)
m.c2564 = Constraint(expr= m.x796 == 0)
m.c2565 = Constraint(expr= m.x797 == 0)
m.c2566 = Constraint(expr= m.x798 == 0)
m.c2567 = Constraint(expr= m.x799 == 0)
m.c2568 = Constraint(expr= m.x802 == 0)
m.c2569 = Constraint(expr= m.x803 == 0)
m.c2570 = Constraint(expr= m.x804 == 0)
m.c2571 = Constraint(expr= m.x805 == 0)
m.c2572 = Constraint(expr= m.x810 == 0)
m.c2573 = Constraint(expr= m.x811 == 0)
m.c2574 = Constraint(expr= m.x817 == 0)
m.c2575 = Constraint(expr= m.x843 == 0)
m.c2576 = Constraint(expr= m.x844 == 0)
m.c2577 = Constraint(expr= m.x845 == 0)
m.c2578 = Constraint(expr= m.x846 == 0)
m.c2579 = Constraint(expr= m.x847 == 0)
m.c2580 = Constraint(expr= m.x852 == 0)
m.c2581 = Constraint(expr= m.x853 == 0)
m.c2582 = Constraint(expr= m.x987 == 0)
m.c2583 = Constraint(expr= m.x988 == 0)
m.c2584 = Constraint(expr= m.x989 == 0)
m.c2585 = Constraint(expr= m.x990 == 0)
m.c2586 = Constraint(expr= m.x991 == 0)
m.c2587 = Constraint(expr= m.x999 == 0)
m.c2588 = Constraint(expr= m.x1000 == 0)
m.c2589 = Constraint(expr= m.x1001 == 0)
m.c2590 = Constraint(expr= m.x1002 == 0)
m.c2591 = Constraint(expr= m.x1003 == 0)
m.c2592 = Constraint(expr= m.x1018 == 0)
m.c2593 = Constraint(expr= m.x1019 == 0)
m.c2594 = Constraint(expr= m.x1020 == 0)
m.c2595 = Constraint(expr= m.x1021 == 0)
m.c2596 = Constraint(expr= m.x1027 == 0)
m.c2597 = Constraint(expr= m.x1060 == 0)
m.c2598 = Constraint(expr= m.x1061 == 0)
m.c2599 = Constraint(expr= m.x1062 == 0)
m.c2600 = Constraint(expr= m.x1063 == 0)
m.c2601 = Constraint(expr= m.x1101 == 0)
m.c2602 = Constraint(expr= m.x1102 == 0)
m.c2603 = Constraint(expr= m.x1103 == 0)
m.c2604 = Constraint(expr= m.x1104 == 0)
m.c2605 = Constraint(expr= m.x1105 == 0)
m.c2606 = Constraint(expr= m.x1113 == 0)
m.c2607 = Constraint(expr= m.x1114 == 0)
m.c2608 = Constraint(expr= m.x1115 == 0)
m.c2609 = Constraint(expr= m.x1116 == 0)
m.c2610 = Constraint(expr= m.x1117 == 0)
m.c2611 = Constraint(expr= m.x1131 == 0)
m.c2612 = Constraint(expr= m.x1132 == 0)
m.c2613 = Constraint(expr= m.x1133 == 0)
m.c2614 = Constraint(expr= m.x1134 == 0)
m.c2615 = Constraint(expr= m.x1135 == 0)
m.c2616 = Constraint(expr= m.x1155 == 0)
m.c2617 = Constraint(expr= m.x1156 == 0)
m.c2618 = Constraint(expr= m.x1157 == 0)
m.c2619 = Constraint(expr= m.x1158 == 0)
m.c2620 = Constraint(expr= m.x1159 == 0)
m.c2621 = Constraint(expr= m.x1185 == 0)
m.c2622 = Constraint(expr= m.x1186 == 0)
m.c2623 = Constraint(expr= m.x1187 == 0)
m.c2624 = Constraint(expr= m.x1188 == 0)
m.c2625 = Constraint(expr= m.x1189 == 0)
m.c2626 = Constraint(expr= m.x1221 == 0)
m.c2627 = Constraint(expr= m.x1222 == 0)
m.c2628 = Constraint(expr= m.x1223 == 0)
m.c2629 = Constraint(expr= m.x1224 == 0)
m.c2630 = Constraint(expr= m.x1225 == 0)
m.c2631 = Constraint(expr= m.x1230 == 0)
m.c2632 = Constraint(expr= m.x1231 == 0)
m.c2633 = Constraint(expr= m.x1233 == 0)
m.c2634 = Constraint(expr= m.x1234 == 0)
m.c2635 = Constraint(expr= m.x1235 == 0)
m.c2636 = Constraint(expr= m.x1236 == 0)
m.c2637 = Constraint(expr= m.x1237 == 0)
m.c2638 = Constraint(expr= m.x1242 == 0)
m.c2639 = Constraint(expr= m.x1243 == 0)
m.c2640 = Constraint(expr= m.x1297 == 0)
m.c2641 = Constraint(expr= m.x1303 == 0)
m.c2642 = Constraint(expr= m.x1317 == 0)
m.c2643 = Constraint(expr= m.x1318 == 0)
m.c2644 = Constraint(expr= m.x1319 == 0)
m.c2645 = Constraint(expr= m.x1320 == 0)
m.c2646 = Constraint(expr= m.x1321 == 0)
m.c2647 = Constraint(expr= m.x1326 == 0)
m.c2648 = Constraint(expr= m.x1327 == 0)
m.c2649 = Constraint(expr= m.x1335 == 0)
m.c2650 = Constraint(expr= m.x1336 == 0)
m.c2651 = Constraint(expr= m.x1337 == 0)
m.c2652 = Constraint(expr= m.x1338 == 0)
m.c2653 = Constraint(expr= m.x1339 == 0)
m.c2654 = Constraint(expr= m.x1344 == 0)
m.c2655 = Constraint(expr= m.x1345 == 0)
m.c2656 = Constraint(expr= m.x1353 == 0)
m.c2657 = Constraint(expr= m.x1354 == 0)
m.c2658 = Constraint(expr= m.x1355 == 0)
m.c2659 = Constraint(expr= m.x1356 == 0)
m.c2660 = Constraint(expr= m.x1357 == 0)
m.c2661 = Constraint(expr= m.x1365 == 0)
m.c2662 = Constraint(expr= m.x1366 == 0)
m.c2663 = Constraint(expr= m.x1367 == 0)
m.c2664 = Constraint(expr= m.x1368 == 0)
m.c2665 = Constraint(expr= m.x1369 == 0)
m.c2666 = Constraint(expr= m.x1374 == 0)
m.c2667 = Constraint(expr= m.x1375 == 0)
m.c2668 = Constraint(expr= m.x1377 == 0)
m.c2669 = Constraint(expr= m.x1378 == 0)
m.c2670 = Constraint(expr= m.x1379 == 0)
m.c2671 = Constraint(expr= m.x1380 == 0)
m.c2672 = Constraint(expr= m.x1381 == 0)
m.c2673 = Constraint(expr= m.x1421 == 0)
m.c2674 = Constraint(expr= m.x1422 == 0)
m.c2675 = Constraint(expr= m.x1423 == 0)
m.c2676 = Constraint(expr= m.x1432 == 0)
m.c2677 = Constraint(expr= m.x1433 == 0)
m.c2678 = Constraint(expr= m.x1434 == 0)
m.c2679 = Constraint(expr= m.x1435 == 0)
m.c2680 = Constraint(expr= m.x1438 == 0)
m.c2681 = Constraint(expr= m.x1439 == 0)
m.c2682 = Constraint(expr= m.x1440 == 0)
m.c2683 = Constraint(expr= m.x1441 == 0)
m.c2684 = Constraint(expr= m.x1491 == 0)
m.c2685 = Constraint(expr= m.x1492 == 0)
m.c2686 = Constraint(expr= m.x1493 == 0)
m.c2687 = Constraint(expr= m.x1494 == 0)
m.c2688 = Constraint(expr= m.x1495 == 0)
m.c2689 = Constraint(expr= m.x1497 == 0)
m.c2690 = Constraint(expr= m.x1498 == 0)
m.c2691 = Constraint(expr= m.x1499 == 0)
m.c2692 = Constraint(expr= m.x1500 == 0)
m.c2693 = Constraint(expr= m.x1501 == 0)
m.c2694 = Constraint(expr= m.x1503 == 0)
m.c2695 = Constraint(expr= m.x1504 == 0)
m.c2696 = Constraint(expr= m.x1505 == 0)
m.c2697 = Constraint(expr= m.x1506 == 0)
m.c2698 = Constraint(expr= m.x1507 == 0)
m.c2699 = Constraint(expr= m.x1509 == 0)
m.c2700 = Constraint(expr= m.x1510 == 0)
m.c2701 = Constraint(expr= m.x1511 == 0)
m.c2702 = Constraint(expr= m.x1512 == 0)
m.c2703 = Constraint(expr= m.x1513 == 0)
m.c2704 = Constraint(expr= m.x1519 == 0)
m.c2705 = Constraint(expr= m.b1538 == 1)
m.c2706 = Constraint(expr= m.b1544 + m.b1545 == 1)
m.c2707 = Constraint(expr= m.b1550 + m.b1551 + m.b1552 == 1)
m.c2708 = Constraint(expr= m.b1556 + m.b1557 + m.b1558 + m.b1559 == 1)
m.c2709 = Constraint(expr= m.b1562 + m.b1563 + m.b1564 + m.b1565 + m.b1566 == 1)
m.c2710 = Constraint(expr= m.b1568 + m.b1569 + m.b1570 + m.b1571 + m.b1572 + m.b1573 == 1)
m.c2711 = Constraint(expr= - m.b1545 + m.b1552 <= 0)
m.c2712 = Constraint(expr= - m.b1545 - m.b1551 + m.b1558 <= 0)
m.c2713 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 + m.b1564 <= 0)
m.c2714 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 + m.b1570 <= 0)
m.c2715 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 + m.b1576 <= 0)
m.c2716 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 + m.b1582 <= 0)
m.c2717 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 + m.b1588 <= 0)
m.c2718 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 + m.b1594
<= 0)
m.c2719 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
+ m.b1600 <= 0)
m.c2720 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 + m.b1606 <= 0)
m.c2721 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 + m.b1612 <= 0)
m.c2722 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 + m.b1618 <= 0)
m.c2723 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 + m.b1624 <= 0)
m.c2724 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 + m.b1630 <= 0)
m.c2725 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 + m.b1636 <= 0)
m.c2726 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 + m.b1642 <= 0)
m.c2727 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 + m.b1648
<= 0)
m.c2728 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
+ m.b1654 <= 0)
m.c2729 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 + m.b1660 <= 0)
m.c2730 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 + m.b1666 <= 0)
m.c2731 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 + m.b1672 <= 0)
m.c2732 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 + m.b1678 <= 0)
m.c2733 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 + m.b1684 <= 0)
m.c2734 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 + m.b1690 <= 0)
m.c2735 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 + m.b1696 <= 0)
m.c2736 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 + m.b1702
<= 0)
m.c2737 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
+ m.b1708 <= 0)
m.c2738 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 + m.b1714 <= 0)
m.c2739 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 + m.b1720 <= 0)
m.c2740 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 + m.b1726 <= 0)
m.c2741 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 + m.b1732 <= 0)
m.c2742 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 + m.b1738 <= 0)
m.c2743 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 + m.b1744 <= 0)
m.c2744 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 + m.b1750 <= 0)
m.c2745 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 + m.b1756
<= 0)
m.c2746 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
+ m.b1762 <= 0)
m.c2747 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 + m.b1768 <= 0)
m.c2748 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 + m.b1774 <= 0)
m.c2749 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 + m.b1780 <= 0)
m.c2750 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 + m.b1786 <= 0)
m.c2751 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 + m.b1792 <= 0)
m.c2752 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 + m.b1798 <= 0)
m.c2753 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 + m.b1804 <= 0)
m.c2754 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 + m.b1810
<= 0)
m.c2755 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
+ m.b1816 <= 0)
m.c2756 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 + m.b1822 <= 0)
m.c2757 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 + m.b1828 <= 0)
m.c2758 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 + m.b1834 <= 0)
m.c2759 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 + m.b1840 <= 0)
m.c2760 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 + m.b1846 <= 0)
m.c2761 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 + m.b1852 <= 0)
m.c2762 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 + m.b1858 <= 0)
m.c2763 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 + m.b1864
<= 0)
m.c2764 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
+ m.b1870 <= 0)
m.c2765 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 + m.b1876 <= 0)
m.c2766 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 + m.b1882 <= 0)
m.c2767 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 + m.b1888 <= 0)
m.c2768 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 + m.b1894 <= 0)
m.c2769 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 + m.b1900 <= 0)
m.c2770 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 + m.b1906 <= 0)
m.c2771 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 + m.b1912 <= 0)
m.c2772 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 + m.b1918
<= 0)
m.c2773 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
+ m.b1924 <= 0)
m.c2774 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 + m.b1930 <= 0)
m.c2775 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 + m.b1936 <= 0)
m.c2776 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 + m.b1942 <= 0)
m.c2777 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 + m.b1948 <= 0)
m.c2778 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 + m.b1954 <= 0)
m.c2779 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 - m.b1953 + m.b1960 <= 0)
m.c2780 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 - m.b1953 - m.b1959 + m.b1966 <= 0)
m.c2781 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 - m.b1953 - m.b1959 - m.b1965 + m.b1972
<= 0)
m.c2782 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 - m.b1953 - m.b1959 - m.b1965 - m.b1971
+ m.b1978 <= 0)
m.c2783 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 - m.b1953 - m.b1959 - m.b1965 - m.b1971
- m.b1977 + m.b1984 <= 0)
m.c2784 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 - m.b1953 - m.b1959 - m.b1965 - m.b1971
- m.b1977 - m.b1983 + m.b1990 <= 0)
m.c2785 = Constraint(expr= - m.b1545 - m.b1551 - m.b1557 - m.b1563 - m.b1569 - m.b1575 - m.b1581 - m.b1587 - m.b1593
- m.b1599 - m.b1605 - m.b1611 - m.b1617 - m.b1623 - m.b1629 - m.b1635 - m.b1641 - m.b1647
- m.b1653 - m.b1659 - m.b1665 - m.b1671 - m.b1677 - m.b1683 - m.b1689 - m.b1695 - m.b1701
- m.b1707 - m.b1713 - m.b1719 - m.b1725 - m.b1731 - m.b1737 - m.b1743 - m.b1749 - m.b1755
- m.b1761 - m.b1767 - m.b1773 - m.b1779 - m.b1785 - m.b1791 - m.b1797 - m.b1803 - m.b1809
- m.b1815 - m.b1821 - m.b1827 - m.b1833 - m.b1839 - m.b1845 - m.b1851 - m.b1857 - m.b1863
- m.b1869 - m.b1875 - m.b1881 - m.b1887 - m.b1893 - m.b1899 - m.b1905 - m.b1911 - m.b1917
- m.b1923 - m.b1929 - m.b1935 - m.b1941 - m.b1947 - m.b1953 - m.b1959 - m.b1965 - m.b1971
- m.b1977 - m.b1983 - m.b1989 + m.b1996 <= 0)
m.c2786 = Constraint(expr= m.b1553 <= 0)
m.c2787 = Constraint(expr= - m.b1552 + m.b1559 <= 0)
m.c2788 = Constraint(expr= - m.b1552 - m.b1558 + m.b1565 <= 0)
m.c2789 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 + m.b1571 <= 0)
m.c2790 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 + m.b1577 <= 0)
m.c2791 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 + m.b1583 <= 0)
m.c2792 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 + m.b1589 <= 0)
m.c2793 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 + m.b1595 <= 0)
m.c2794 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 + m.b1601
<= 0)
m.c2795 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
+ m.b1607 <= 0)
m.c2796 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 + m.b1613 <= 0)
m.c2797 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 + m.b1619 <= 0)
m.c2798 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 + m.b1625 <= 0)
m.c2799 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 + m.b1631 <= 0)
m.c2800 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 + m.b1637 <= 0)
m.c2801 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 + m.b1643 <= 0)
m.c2802 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 + m.b1649 <= 0)
m.c2803 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 + m.b1655
<= 0)
m.c2804 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
+ m.b1661 <= 0)
m.c2805 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 + m.b1667 <= 0)
m.c2806 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 + m.b1673 <= 0)
m.c2807 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 + m.b1679 <= 0)
m.c2808 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 + m.b1685 <= 0)
m.c2809 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 + m.b1691 <= 0)
m.c2810 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 + m.b1697 <= 0)
m.c2811 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 + m.b1703 <= 0)
m.c2812 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 + m.b1709
<= 0)
m.c2813 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
+ m.b1715 <= 0)
m.c2814 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 + m.b1721 <= 0)
m.c2815 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 + m.b1727 <= 0)
m.c2816 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 + m.b1733 <= 0)
m.c2817 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 + m.b1739 <= 0)
m.c2818 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 + m.b1745 <= 0)
m.c2819 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 + m.b1751 <= 0)
m.c2820 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 + m.b1757 <= 0)
m.c2821 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 + m.b1763
<= 0)
m.c2822 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
+ m.b1769 <= 0)
m.c2823 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 + m.b1775 <= 0)
m.c2824 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 + m.b1781 <= 0)
m.c2825 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 + m.b1787 <= 0)
m.c2826 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 + m.b1793 <= 0)
m.c2827 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 + m.b1799 <= 0)
m.c2828 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 + m.b1805 <= 0)
m.c2829 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 + m.b1811 <= 0)
m.c2830 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 + m.b1817
<= 0)
m.c2831 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
+ m.b1823 <= 0)
m.c2832 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 + m.b1829 <= 0)
m.c2833 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 + m.b1835 <= 0)
m.c2834 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 + m.b1841 <= 0)
m.c2835 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 + m.b1847 <= 0)
m.c2836 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 + m.b1853 <= 0)
m.c2837 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 + m.b1859 <= 0)
m.c2838 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 + m.b1865 <= 0)
m.c2839 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 + m.b1871
<= 0)
m.c2840 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
+ m.b1877 <= 0)
m.c2841 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 + m.b1883 <= 0)
m.c2842 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 + m.b1889 <= 0)
m.c2843 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 + m.b1895 <= 0)
m.c2844 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 + m.b1901 <= 0)
m.c2845 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 + m.b1907 <= 0)
m.c2846 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 + m.b1913 <= 0)
m.c2847 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 + m.b1919 <= 0)
m.c2848 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 + m.b1925
<= 0)
m.c2849 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
+ m.b1931 <= 0)
m.c2850 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 + m.b1937 <= 0)
m.c2851 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 + m.b1943 <= 0)
m.c2852 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 + m.b1949 <= 0)
m.c2853 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 + m.b1955 <= 0)
m.c2854 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 - m.b1954 + m.b1961 <= 0)
m.c2855 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 - m.b1954 - m.b1960 + m.b1967 <= 0)
m.c2856 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 - m.b1954 - m.b1960 - m.b1966 + m.b1973 <= 0)
m.c2857 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 - m.b1954 - m.b1960 - m.b1966 - m.b1972 + m.b1979
<= 0)
m.c2858 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 - m.b1954 - m.b1960 - m.b1966 - m.b1972 - m.b1978
+ m.b1985 <= 0)
m.c2859 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 - m.b1954 - m.b1960 - m.b1966 - m.b1972 - m.b1978
- m.b1984 + m.b1991 <= 0)
m.c2860 = Constraint(expr= - m.b1552 - m.b1558 - m.b1564 - m.b1570 - m.b1576 - m.b1582 - m.b1588 - m.b1594 - m.b1600
- m.b1606 - m.b1612 - m.b1618 - m.b1624 - m.b1630 - m.b1636 - m.b1642 - m.b1648 - m.b1654
- m.b1660 - m.b1666 - m.b1672 - m.b1678 - m.b1684 - m.b1690 - m.b1696 - m.b1702 - m.b1708
- m.b1714 - m.b1720 - m.b1726 - m.b1732 - m.b1738 - m.b1744 - m.b1750 - m.b1756 - m.b1762
- m.b1768 - m.b1774 - m.b1780 - m.b1786 - m.b1792 - m.b1798 - m.b1804 - m.b1810 - m.b1816
- m.b1822 - m.b1828 - m.b1834 - m.b1840 - m.b1846 - m.b1852 - m.b1858 - m.b1864 - m.b1870
- m.b1876 - m.b1882 - m.b1888 - m.b1894 - m.b1900 - m.b1906 - m.b1912 - m.b1918 - m.b1924
- m.b1930 - m.b1936 - m.b1942 - m.b1948 - m.b1954 - m.b1960 - m.b1966 - m.b1972 - m.b1978
- m.b1984 - m.b1990 + m.b1997 <= 0)
m.c2861 = Constraint(expr= m.b1554 <= 0)
m.c2862 = Constraint(expr= m.b1560 <= 0)
m.c2863 = Constraint(expr= - m.b1559 + m.b1566 <= 0)
m.c2864 = Constraint(expr= - m.b1559 - m.b1565 + m.b1572 <= 0)
m.c2865 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 + m.b1578 <= 0)
m.c2866 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 + m.b1584 <= 0)
m.c2867 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 + m.b1590 <= 0)
m.c2868 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 + m.b1596 <= 0)
m.c2869 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 + m.b1602 <= 0)
m.c2870 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 + m.b1608
<= 0)
m.c2871 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
+ m.b1614 <= 0)
m.c2872 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 + m.b1620 <= 0)
m.c2873 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 + m.b1626 <= 0)
m.c2874 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 + m.b1632 <= 0)
m.c2875 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 + m.b1638 <= 0)
m.c2876 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 + m.b1644 <= 0)
m.c2877 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 + m.b1650 <= 0)
m.c2878 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 + m.b1656 <= 0)
m.c2879 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 + m.b1662
<= 0)
m.c2880 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
+ m.b1668 <= 0)
m.c2881 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 + m.b1674 <= 0)
m.c2882 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 + m.b1680 <= 0)
m.c2883 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 + m.b1686 <= 0)
m.c2884 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 + m.b1692 <= 0)
m.c2885 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 + m.b1698 <= 0)
m.c2886 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 + m.b1704 <= 0)
m.c2887 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 + m.b1710 <= 0)
m.c2888 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 + m.b1716
<= 0)
m.c2889 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
+ m.b1722 <= 0)
m.c2890 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 + m.b1728 <= 0)
m.c2891 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 + m.b1734 <= 0)
m.c2892 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 + m.b1740 <= 0)
m.c2893 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 + m.b1746 <= 0)
m.c2894 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 + m.b1752 <= 0)
m.c2895 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 + m.b1758 <= 0)
m.c2896 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 + m.b1764 <= 0)
m.c2897 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 + m.b1770
<= 0)
m.c2898 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
+ m.b1776 <= 0)
m.c2899 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 + m.b1782 <= 0)
m.c2900 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 + m.b1788 <= 0)
m.c2901 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 + m.b1794 <= 0)
m.c2902 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 + m.b1800 <= 0)
m.c2903 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 + m.b1806 <= 0)
m.c2904 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 + m.b1812 <= 0)
m.c2905 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 + m.b1818 <= 0)
m.c2906 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 + m.b1824
<= 0)
m.c2907 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
+ m.b1830 <= 0)
m.c2908 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 + m.b1836 <= 0)
m.c2909 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 + m.b1842 <= 0)
m.c2910 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 + m.b1848 <= 0)
m.c2911 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 + m.b1854 <= 0)
m.c2912 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 + m.b1860 <= 0)
m.c2913 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 + m.b1866 <= 0)
m.c2914 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 + m.b1872 <= 0)
m.c2915 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 + m.b1878
<= 0)
m.c2916 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
+ m.b1884 <= 0)
m.c2917 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 + m.b1890 <= 0)
m.c2918 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 + m.b1896 <= 0)
m.c2919 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 + m.b1902 <= 0)
m.c2920 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 + m.b1908 <= 0)
m.c2921 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 + m.b1914 <= 0)
m.c2922 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 + m.b1920 <= 0)
m.c2923 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 + m.b1926 <= 0)
m.c2924 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 + m.b1932
<= 0)
m.c2925 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
+ m.b1938 <= 0)
m.c2926 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 + m.b1944 <= 0)
m.c2927 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 + m.b1950 <= 0)
m.c2928 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 + m.b1956 <= 0)
m.c2929 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 - m.b1955 + m.b1962 <= 0)
m.c2930 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 - m.b1955 - m.b1961 + m.b1968 <= 0)
m.c2931 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 - m.b1955 - m.b1961 - m.b1967 + m.b1974 <= 0)
m.c2932 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 - m.b1955 - m.b1961 - m.b1967 - m.b1973 + m.b1980 <= 0)
m.c2933 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 - m.b1955 - m.b1961 - m.b1967 - m.b1973 - m.b1979 + m.b1986
<= 0)
m.c2934 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 - m.b1955 - m.b1961 - m.b1967 - m.b1973 - m.b1979 - m.b1985
+ m.b1992 <= 0)
m.c2935 = Constraint(expr= - m.b1559 - m.b1565 - m.b1571 - m.b1577 - m.b1583 - m.b1589 - m.b1595 - m.b1601 - m.b1607
- m.b1613 - m.b1619 - m.b1625 - m.b1631 - m.b1637 - m.b1643 - m.b1649 - m.b1655 - m.b1661
- m.b1667 - m.b1673 - m.b1679 - m.b1685 - m.b1691 - m.b1697 - m.b1703 - m.b1709 - m.b1715
- m.b1721 - m.b1727 - m.b1733 - m.b1739 - m.b1745 - m.b1751 - m.b1757 - m.b1763 - m.b1769
- m.b1775 - m.b1781 - m.b1787 - m.b1793 - m.b1799 - m.b1805 - m.b1811 - m.b1817 - m.b1823
- m.b1829 - m.b1835 - m.b1841 - m.b1847 - m.b1853 - m.b1859 - m.b1865 - m.b1871 - m.b1877
- m.b1883 - m.b1889 - m.b1895 - m.b1901 - m.b1907 - m.b1913 - m.b1919 - m.b1925 - m.b1931
- m.b1937 - m.b1943 - m.b1949 - m.b1955 - m.b1961 - m.b1967 - m.b1973 - m.b1979 - m.b1985
- m.b1991 + m.b1998 <= 0)
m.c2936 = Constraint(expr= m.b1555 <= 0)
m.c2937 = Constraint(expr= m.b1561 <= 0)
m.c2938 = Constraint(expr= m.b1567 <= 0)
m.c2939 = Constraint(expr= - m.b1566 + m.b1573 <= 0)
m.c2940 = Constraint(expr= - m.b1566 - m.b1572 + m.b1579 <= 0)
m.c2941 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 + m.b1585 <= 0)
m.c2942 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 + m.b1591 <= 0)
m.c2943 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 + m.b1597 <= 0)
m.c2944 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 + m.b1603 <= 0)
m.c2945 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 + m.b1609 <= 0)
m.c2946 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 + m.b1615
<= 0)
m.c2947 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
+ m.b1621 <= 0)
m.c2948 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 + m.b1627 <= 0)
m.c2949 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 + m.b1633 <= 0)
m.c2950 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 + m.b1639 <= 0)
m.c2951 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 + m.b1645 <= 0)
m.c2952 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 + m.b1651 <= 0)
m.c2953 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 + m.b1657 <= 0)
m.c2954 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 + m.b1663 <= 0)
m.c2955 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 + m.b1669
<= 0)
m.c2956 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
+ m.b1675 <= 0)
m.c2957 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 + m.b1681 <= 0)
m.c2958 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 + m.b1687 <= 0)
m.c2959 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 + m.b1693 <= 0)
m.c2960 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 + m.b1699 <= 0)
m.c2961 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 + m.b1705 <= 0)
m.c2962 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 + m.b1711 <= 0)
m.c2963 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 + m.b1717 <= 0)
m.c2964 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 + m.b1723
<= 0)
m.c2965 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
+ m.b1729 <= 0)
m.c2966 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 + m.b1735 <= 0)
m.c2967 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 + m.b1741 <= 0)
m.c2968 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 + m.b1747 <= 0)
m.c2969 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 + m.b1753 <= 0)
m.c2970 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 + m.b1759 <= 0)
m.c2971 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 + m.b1765 <= 0)
m.c2972 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 + m.b1771 <= 0)
m.c2973 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 + m.b1777
<= 0)
m.c2974 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
+ m.b1783 <= 0)
m.c2975 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 + m.b1789 <= 0)
m.c2976 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 + m.b1795 <= 0)
m.c2977 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 + m.b1801 <= 0)
m.c2978 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 + m.b1807 <= 0)
m.c2979 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 + m.b1813 <= 0)
m.c2980 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 + m.b1819 <= 0)
m.c2981 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 + m.b1825 <= 0)
m.c2982 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 + m.b1831
<= 0)
m.c2983 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
+ m.b1837 <= 0)
m.c2984 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 + m.b1843 <= 0)
m.c2985 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 + m.b1849 <= 0)
m.c2986 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 + m.b1855 <= 0)
m.c2987 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 + m.b1861 <= 0)
m.c2988 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 + m.b1867 <= 0)
m.c2989 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 + m.b1873 <= 0)
m.c2990 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 + m.b1879 <= 0)
m.c2991 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 + m.b1885
<= 0)
m.c2992 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
+ m.b1891 <= 0)
m.c2993 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 + m.b1897 <= 0)
m.c2994 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 + m.b1903 <= 0)
m.c2995 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 + m.b1909 <= 0)
m.c2996 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 + m.b1915 <= 0)
m.c2997 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 + m.b1921 <= 0)
m.c2998 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 + m.b1927 <= 0)
m.c2999 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 + m.b1933 <= 0)
m.c3000 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 + m.b1939
<= 0)
m.c3001 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
+ m.b1945 <= 0)
m.c3002 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 + m.b1951 <= 0)
m.c3003 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 + m.b1957 <= 0)
m.c3004 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 - m.b1956 + m.b1963 <= 0)
m.c3005 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 - m.b1956 - m.b1962 + m.b1969 <= 0)
m.c3006 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 - m.b1956 - m.b1962 - m.b1968 + m.b1975 <= 0)
m.c3007 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 - m.b1956 - m.b1962 - m.b1968 - m.b1974 + m.b1981 <= 0)
m.c3008 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 - m.b1956 - m.b1962 - m.b1968 - m.b1974 - m.b1980 + m.b1987 <= 0)
m.c3009 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 - m.b1956 - m.b1962 - m.b1968 - m.b1974 - m.b1980 - m.b1986 + m.b1993
<= 0)
m.c3010 = Constraint(expr= - m.b1566 - m.b1572 - m.b1578 - m.b1584 - m.b1590 - m.b1596 - m.b1602 - m.b1608 - m.b1614
- m.b1620 - m.b1626 - m.b1632 - m.b1638 - m.b1644 - m.b1650 - m.b1656 - m.b1662 - m.b1668
- m.b1674 - m.b1680 - m.b1686 - m.b1692 - m.b1698 - m.b1704 - m.b1710 - m.b1716 - m.b1722
- m.b1728 - m.b1734 - m.b1740 - m.b1746 - m.b1752 - m.b1758 - m.b1764 - m.b1770 - m.b1776
- m.b1782 - m.b1788 - m.b1794 - m.b1800 - m.b1806 - m.b1812 - m.b1818 - m.b1824 - m.b1830
- m.b1836 - m.b1842 - m.b1848 - m.b1854 - m.b1860 - m.b1866 - m.b1872 - m.b1878 - m.b1884
- m.b1890 - m.b1896 - m.b1902 - m.b1908 - m.b1914 - m.b1920 - m.b1926 - m.b1932 - m.b1938
- m.b1944 - m.b1950 - m.b1956 - m.b1962 - m.b1968 - m.b1974 - m.b1980 - m.b1986 - m.b1992
+ m.b1999 <= 0)
m.c3011 = Constraint(expr= m.b1574 + m.b1575 + m.b1576 + m.b1577 + m.b1578 + m.b1579 == 1)
m.c3012 = Constraint(expr= m.b1580 + m.b1581 + m.b1582 + m.b1583 + m.b1584 + m.b1585 == 1)
m.c3013 = Constraint(expr= m.b1586 + m.b1587 + m.b1588 + m.b1589 + m.b1590 + m.b1591 == 1)
m.c3014 = Constraint(expr= m.b1592 + m.b1593 + m.b1594 + m.b1595 + m.b1596 + m.b1597 == 1)
m.c3015 = Constraint(expr= m.b1598 + m.b1599 + m.b1600 + m.b1601 + m.b1602 + m.b1603 == 1)
m.c3016 = Constraint(expr= m.b1604 + m.b1605 + m.b1606 + m.b1607 + m.b1608 + m.b1609 == 1)
m.c3017 = Constraint(expr= m.b1610 + m.b1611 + m.b1612 + m.b1613 + m.b1614 + m.b1615 == 1)
m.c3018 = Constraint(expr= m.b1616 + m.b1617 + m.b1618 + m.b1619 + m.b1620 + m.b1621 == 1)
m.c3019 = Constraint(expr= m.b1622 + m.b1623 + m.b1624 + m.b1625 + m.b1626 + m.b1627 == 1)
m.c3020 = Constraint(expr= m.b1628 + m.b1629 + m.b1630 + m.b1631 + m.b1632 + m.b1633 == 1)
m.c3021 = Constraint(expr= m.b1634 + m.b1635 + m.b1636 + m.b1637 + m.b1638 + m.b1639 == 1)
m.c3022 = Constraint(expr= m.b1640 + m.b1641 + m.b1642 + m.b1643 + m.b1644 + m.b1645 == 1)
m.c3023 = Constraint(expr= m.b1646 + m.b1647 + m.b1648 + m.b1649 + m.b1650 + m.b1651 == 1)
m.c3024 = Constraint(expr= m.b1652 + m.b1653 + m.b1654 + m.b1655 + m.b1656 + m.b1657 == 1)
m.c3025 = Constraint(expr= m.b1658 + m.b1659 + m.b1660 + m.b1661 + m.b1662 + m.b1663 == 1)
m.c3026 = Constraint(expr= m.b1664 + m.b1665 + m.b1666 + m.b1667 + m.b1668 + m.b1669 == 1)
m.c3027 = Constraint(expr= m.b1670 + m.b1671 + m.b1672 + m.b1673 + m.b1674 + m.b1675 == 1)
m.c3028 = Constraint(expr= m.b1676 + m.b1677 + m.b1678 + m.b1679 + m.b1680 + m.b1681 == 1)
m.c3029 = Constraint(expr= m.b1682 + m.b1683 + m.b1684 + m.b1685 + m.b1686 + m.b1687 == 1)
m.c3030 = Constraint(expr= m.b1688 + m.b1689 + m.b1690 + m.b1691 + m.b1692 + m.b1693 == 1)
m.c3031 = Constraint(expr= m.b1694 + m.b1695 + m.b1696 + m.b1697 + m.b1698 + m.b1699 == 1)
m.c3032 = Constraint(expr= m.b1700 + m.b1701 + m.b1702 + m.b1703 + m.b1704 + m.b1705 == 1)
m.c3033 = Constraint(expr= m.b1706 + m.b1707 + m.b1708 + m.b1709 + m.b1710 + m.b1711 == 1)
m.c3034 = Constraint(expr= m.b1712 + m.b1713 + m.b1714 + m.b1715 + m.b1716 + m.b1717 == 1)
m.c3035 = Constraint(expr= m.b1718 + m.b1719 + m.b1720 + m.b1721 + m.b1722 + m.b1723 == 1)
m.c3036 = Constraint(expr= m.b1724 + m.b1725 + m.b1726 + m.b1727 + m.b1728 + m.b1729 == 1)
m.c3037 = Constraint(expr= m.b1730 + m.b1731 + m.b1732 + m.b1733 + m.b1734 + m.b1735 == 1)
m.c3038 = Constraint(expr= m.b1736 + m.b1737 + m.b1738 + m.b1739 + m.b1740 + m.b1741 == 1)
m.c3039 = Constraint(expr= m.b1742 + m.b1743 + m.b1744 + m.b1745 + m.b1746 + m.b1747 == 1)
m.c3040 = Constraint(expr= m.b1748 + m.b1749 + m.b1750 + m.b1751 + m.b1752 + m.b1753 == 1)
m.c3041 = Constraint(expr= m.b1754 + m.b1755 + m.b1756 + m.b1757 + m.b1758 + m.b1759 == 1)
m.c3042 = Constraint(expr= m.b1760 + m.b1761 + m.b1762 + m.b1763 + m.b1764 + m.b1765 == 1)
m.c3043 = Constraint(expr= m.b1766 + m.b1767 + m.b1768 + m.b1769 + m.b1770 + m.b1771 == 1)
m.c3044 = Constraint(expr= m.b1772 + m.b1773 + m.b1774 + m.b1775 + m.b1776 + m.b1777 == 1)
m.c3045 = Constraint(expr= m.b1778 + m.b1779 + m.b1780 + m.b1781 + m.b1782 + m.b1783 == 1)
m.c3046 = Constraint(expr= m.b1784 + m.b1785 + m.b1786 + m.b1787 + m.b1788 + m.b1789 == 1)
m.c3047 = Constraint(expr= m.b1790 + m.b1791 + m.b1792 + m.b1793 + m.b1794 + m.b1795 == 1)
m.c3048 = Constraint(expr= m.b1796 + m.b1797 + m.b1798 + m.b1799 + m.b1800 + m.b1801 == 1)
m.c3049 = Constraint(expr= m.b1802 + m.b1803 + m.b1804 + m.b1805 + m.b1806 + m.b1807 == 1)
m.c3050 = Constraint(expr= m.b1808 + m.b1809 + m.b1810 + m.b1811 + m.b1812 + m.b1813 == 1)
m.c3051 = Constraint(expr= m.b1814 + m.b1815 + m.b1816 + m.b1817 + m.b1818 + m.b1819 == 1)
m.c3052 = Constraint(expr= m.b1820 + m.b1821 + m.b1822 + m.b1823 + m.b1824 + m.b1825 == 1)
m.c3053 = Constraint(expr= m.b1826 + m.b1827 + m.b1828 + m.b1829 + m.b1830 + m.b1831 == 1)
m.c3054 = Constraint(expr= m.b1832 + m.b1833 + m.b1834 + m.b1835 + m.b1836 + m.b1837 == 1)
m.c3055 = Constraint(expr= m.b1838 + m.b1839 + m.b1840 + m.b1841 + m.b1842 + m.b1843 == 1)
m.c3056 = Constraint(expr= m.b1844 + m.b1845 + m.b1846 + m.b1847 + m.b1848 + m.b1849 == 1)
m.c3057 = Constraint(expr= m.b1850 + m.b1851 + m.b1852 + m.b1853 + m.b1854 + m.b1855 == 1)
m.c3058 = Constraint(expr= m.b1856 + m.b1857 + m.b1858 + m.b1859 + m.b1860 + m.b1861 == 1)
m.c3059 = Constraint(expr= m.b1862 + m.b1863 + m.b1864 + m.b1865 + m.b1866 + m.b1867 == 1)
m.c3060 = Constraint(expr= m.b1868 + m.b1869 + m.b1870 + m.b1871 + m.b1872 + m.b1873 == 1)
m.c3061 = Constraint(expr= m.b1874 + m.b1875 + m.b1876 + m.b1877 + m.b1878 + m.b1879 == 1)
m.c3062 = Constraint(expr= m.b1880 + m.b1881 + m.b1882 + m.b1883 + m.b1884 + m.b1885 == 1)
m.c3063 = Constraint(expr= m.b1886 + m.b1887 + m.b1888 + m.b1889 + m.b1890 + m.b1891 == 1)
m.c3064 = Constraint(expr= m.b1892 + m.b1893 + m.b1894 + m.b1895 + m.b1896 + m.b1897 == 1)
m.c3065 = Constraint(expr= m.b1898 + m.b1899 + m.b1900 + m.b1901 + m.b1902 + m.b1903 == 1)
m.c3066 = Constraint(expr= m.b1904 + m.b1905 + m.b1906 + m.b1907 + m.b1908 + m.b1909 == 1)
m.c3067 = Constraint(expr= m.b1910 + m.b1911 + m.b1912 + m.b1913 + m.b1914 + m.b1915 == 1)
m.c3068 = Constraint(expr= m.b1916 + m.b1917 + m.b1918 + m.b1919 + m.b1920 + m.b1921 == 1)
m.c3069 = Constraint(expr= m.b1922 + m.b1923 + m.b1924 + m.b1925 + m.b1926 + m.b1927 == 1)
m.c3070 = Constraint(expr= m.b1928 + m.b1929 + m.b1930 + m.b1931 + m.b1932 + m.b1933 == 1)
m.c3071 = Constraint(expr= m.b1934 + m.b1935 + m.b1936 + m.b1937 + m.b1938 + m.b1939 == 1)
m.c3072 = Constraint(expr= m.b1940 + m.b1941 + m.b1942 + m.b1943 + m.b1944 + m.b1945 == 1)
m.c3073 = Constraint(expr= m.b1946 + m.b1947 + m.b1948 + m.b1949 + m.b1950 + m.b1951 == 1)
m.c3074 = Constraint(expr= m.b1952 + m.b1953 + m.b1954 + m.b1955 + m.b1956 + m.b1957 == 1)
m.c3075 = Constraint(expr= m.b1958 + m.b1959 + m.b1960 + m.b1961 + m.b1962 + m.b1963 == 1)
m.c3076 = Constraint(expr= m.b1964 + m.b1965 + m.b1966 + m.b1967 + m.b1968 + m.b1969 == 1)
m.c3077 = Constraint(expr= m.b1970 + m.b1971 + m.b1972 + m.b1973 + m.b1974 + m.b1975 == 1)
m.c3078 = Constraint(expr= m.b1976 + m.b1977 + m.b1978 + m.b1979 + m.b1980 + m.b1981 == 1)
m.c3079 = Constraint(expr= m.b1982 + m.b1983 + m.b1984 + m.b1985 + m.b1986 + m.b1987 == 1)
m.c3080 = Constraint(expr= m.b1988 + m.b1989 + m.b1990 + m.b1991 + m.b1992 + m.b1993 == 1)
m.c3081 = Constraint(expr= m.b1994 + m.b1995 + m.b1996 + m.b1997 + m.b1998 + m.b1999 == 1)
|
<reponame>phil65/PrettyQt
from __future__ import annotations
from typing import Literal
from prettyqt.qt import QtGui
from prettyqt.utils import InvalidParamError, bidict, mappers, types
mod = QtGui.QImageIOHandler
IMAGE_OPTION = bidict(
size=mod.ImageOption.Size,
clip_rect=mod.ImageOption.ClipRect,
scaled_size=mod.ImageOption.ScaledSize,
scaled_clip_rect=mod.ImageOption.ScaledClipRect,
description=mod.ImageOption.Description,
compression_ratio=mod.ImageOption.CompressionRatio,
gamma=mod.ImageOption.Gamma,
quality=mod.ImageOption.Quality,
name=mod.ImageOption.Name,
subtype=mod.ImageOption.SubType,
incremental_reading=mod.ImageOption.IncrementalReading,
endianness=mod.ImageOption.Endianness,
animation=mod.ImageOption.Animation,
background_color=mod.ImageOption.BackgroundColor,
# image_format=mod.ImageOption.ImageFormat,
supported_sub_types=mod.ImageOption.SupportedSubTypes,
optimized_write=mod.ImageOption.OptimizedWrite,
progressive_scan_write=mod.ImageOption.ProgressiveScanWrite,
image_transformation=mod.ImageOption.ImageTransformation,
)
ImageOptionStr = Literal[
"size",
"clip_rect",
"scaled_size",
"scaled_clip_rect",
"description",
"compression_ratio",
"gamma",
"quality",
"name",
"subtype",
"incremental_reading",
"endianness",
"animation",
"background_color",
# "image_format",
"supported_sub_types",
"optimized_write",
"progressive_scan_write",
"image_transformation",
]
TRANSFORMATION = mappers.FlagMap(
mod.Transformation,
none=mod.Transformation.TransformationNone,
mirror=mod.Transformation.TransformationMirror,
flip=mod.Transformation.TransformationFlip,
rotate_180=mod.Transformation.TransformationRotate180,
roate_90=mod.Transformation.TransformationRotate90,
mirror_and_rotate_90=mod.Transformation.TransformationMirrorAndRotate90,
flip_and_rotate_90=mod.Transformation.TransformationFlipAndRotate90,
rotate_270=mod.Transformation.TransformationRotate270,
)
TransformationStr = Literal[
"none",
"mirror",
"flip",
"rotate_180",
"roate_90",
"mirror_and_rotate_90",
"flip_and_rotate_90",
"rotate_270",
]
class ImageIOHandler(mod):
def __getitem__(self, key: ImageOptionStr) -> types.Variant:
return self.get_option(key)
def __setitem__(self, key: ImageOptionStr, value: types.Variant):
self.set_option(key, value)
def get_format(self) -> str:
return bytes(self.format()).decode()
def set_option(self, option: ImageOptionStr, value: types.Variant):
"""Set option to given value.
Args:
option: option to use
value: value to set
Raises:
InvalidParamError: option does not exist
"""
if option not in IMAGE_OPTION:
raise InvalidParamError(option, IMAGE_OPTION)
self.setOption(IMAGE_OPTION[option], value)
def get_option(self, option: ImageOptionStr) -> types.Variant:
"""Return the value assigned to option.
Args:
option: option to get
Returns:
option
"""
if option not in IMAGE_OPTION:
raise InvalidParamError(option, IMAGE_OPTION)
return self.option(IMAGE_OPTION[option])
def supports_option(self, option: ImageOptionStr) -> bool:
"""Return whether the image handler supports given option.
Args:
option: option to check
Returns:
option
"""
if option not in IMAGE_OPTION:
raise InvalidParamError(option, IMAGE_OPTION)
return self.supportsOption(IMAGE_OPTION[option])
if __name__ == "__main__":
writer = ImageIOHandler()
|
from django.conf.urls import url, include
from django.views.generic import RedirectView
from . import views
app_name = 'administrator'
urlpatterns = [
#Regular Expression r'regularExprsHere'
# /login/
url(r'^$', views.loginindex, name='loginindex'),
url(r'^blog/$', views.viewlogin, name='viewlogin'),
# Not override the logout url.
url(r'^log_out/$', views.viewlogout, name='viewlogout'),
# /blog/
url(r'^remove/(?P<idpost>[0-9]+)', views.blog_delete, name='blog_delete'),
url(r'^blog/add/$', views.blog_create, name='blog_create'),
url(r'^blog/edit/(?P<idpost>[0-9]+)/$', views.blog_update, name='blog_update'),
url(r'^savepost/(?P<idpost>[0-9]+)', views.savepost, name='savepost'),
# /aboutme/
url(r'^aboutme/$', views.aboutme, name='aboutme'),
url(r'^saveme/(?P<id>[0-9]+)', views.saveaboutme, name='saveaboutme'),
# /cv/resume
url(r'^cv/$', views.ResumeIndexView.as_view(), name='resume_index'),
url(r'^cv/resume/add/$', views.ResumeCreate.as_view(), name='resume_create'),
url(r'^cv/resume/edit/(?P<pk>[0-9]+)/$', views.ResumeUpdate.as_view(), name='resume_update'),
url(r'^cv/resume/(?P<pk>[0-9]+)/delete/$', views.ResumeDelete.as_view(), name='resume_delete'),
url(r'^cv/resume/display_change/(?P<id>[0-9]+)/$', views.displayChange, name='display_change'),
# /cv/experience
url(r'^cv/experience/$', views.ExperienceIndexView.as_view(), name='experience_index'),
url(r'^cv/experience/add/$', views.ExperienceCreate.as_view(), name='experience_create'),
url(r'^cv/experience/edit/(?P<pk>[0-9]+)/$', views.ExperienceUpdate.as_view(), name='experience_update'),
url(r'^cv/experience/(?P<pk>[0-9]+)/delete/$', views.ExperienceDelete.as_view(), name='experience_delete'),
# /cv/education
url(r'^cv/education/$', views.EducationIndexView.as_view(), name='education_index'),
url(r'^cv/education/add/$', views.EducationCreate.as_view(), name='education_create'),
url(r'^cv/education/edit/(?P<pk>[0-9]+)/$', views.EducationUpdate.as_view(), name='education_update'),
url(r'^cv/education/(?P<pk>[0-9]+)/delete/$', views.EducationDelete.as_view(), name='education_delete'),
# /skill/fields
url(r'^skill/fields/$', views.FieldIndexView.as_view(), name='field_index'),
url(r'^skill/fields/add/$', views.FieldCreate.as_view(), name='field_create'),
url(r'^skill/fields/edit/(?P<pk>[0-9]+)/$', views.FieldUpdate.as_view(), name='field_update'),
url(r'^skill/fields/(?P<pk>[0-9]+)/delete/$', views.FieldDelete.as_view(), name='field_delete'),
# /skill/skills
url(r'^skill/skills/$', views.SkillIndexView.as_view(), name='skill_index'),
url(r'^skill/skills/add/$', views.SkillCreate.as_view(), name='skill_create'),
url(r'^skill/skills/edit/(?P<pk>[0-9]+)/$', views.SkillUpdate.as_view(), name='skill_update'),
url(r'^skill/skills/(?P<pk>[0-9]+)/delete/$', views.SkillDelete.as_view(), name='skill_delete'),
] |
# coding: utf-8
"""
EVE Swagger Interface
An OpenAPI for EVE Online # noqa: E501
OpenAPI spec version: 0.8.0
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""
from __future__ import absolute_import
import re # noqa: F401
# python 2 and python 3 compatibility library
import six
from swagger_client.api_client import ApiClient
class PlanetaryInteractionApi(object):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
Ref: https://github.com/swagger-api/swagger-codegen
"""
def __init__(self, api_client=None):
if api_client is None:
api_client = ApiClient()
self.api_client = api_client
def get_characters_character_id_planets(self, character_id, **kwargs): # noqa: E501
"""Get colonies # noqa: E501
Returns a list of all planetary colonies owned by a character. --- This route is cached for up to 600 seconds # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_characters_character_id_planets(character_id, async=True)
>>> result = thread.get()
:param async bool
:param int character_id: An EVE character ID (required)
:param str datasource: The server name you would like data from
:param str token: Access token to use if unable to set a header
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: list[GetCharactersCharacterIdPlanets200Ok]
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return self.get_characters_character_id_planets_with_http_info(character_id, **kwargs) # noqa: E501
else:
(data) = self.get_characters_character_id_planets_with_http_info(character_id, **kwargs) # noqa: E501
return data
def get_characters_character_id_planets_with_http_info(self, character_id, **kwargs): # noqa: E501
"""Get colonies # noqa: E501
Returns a list of all planetary colonies owned by a character. --- This route is cached for up to 600 seconds # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_characters_character_id_planets_with_http_info(character_id, async=True)
>>> result = thread.get()
:param async bool
:param int character_id: An EVE character ID (required)
:param str datasource: The server name you would like data from
:param str token: Access token to use if unable to set a header
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: list[GetCharactersCharacterIdPlanets200Ok]
If the method is called asynchronously,
returns the request thread.
"""
all_params = ['character_id', 'datasource', 'token', 'user_agent', 'x_user_agent'] # noqa: E501
all_params.append('async')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method get_characters_character_id_planets" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'character_id' is set
if ('character_id' not in params or
params['character_id'] is None):
raise ValueError("Missing the required parameter `character_id` when calling `get_characters_character_id_planets`") # noqa: E501
if 'character_id' in params and params['character_id'] < 1: # noqa: E501
raise ValueError("Invalid value for parameter `character_id` when calling `get_characters_character_id_planets`, must be a value greater than or equal to `1`") # noqa: E501
collection_formats = {}
path_params = {}
if 'character_id' in params:
path_params['character_id'] = params['character_id'] # noqa: E501
query_params = []
if 'datasource' in params:
query_params.append(('datasource', params['datasource'])) # noqa: E501
if 'token' in params:
query_params.append(('token', params['token'])) # noqa: E501
if 'user_agent' in params:
query_params.append(('user_agent', params['user_agent'])) # noqa: E501
header_params = {}
if 'x_user_agent' in params:
header_params['X-User-Agent'] = params['x_user_agent'] # noqa: E501
form_params = []
local_var_files = {}
body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501
# Authentication setting
auth_settings = ['evesso'] # noqa: E501
return self.api_client.call_api(
'/v1/characters/{character_id}/planets/', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='list[GetCharactersCharacterIdPlanets200Ok]', # noqa: E501
auth_settings=auth_settings,
async=params.get('async'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
def get_characters_character_id_planets_planet_id(self, character_id, planet_id, **kwargs): # noqa: E501
"""Get colony layout # noqa: E501
Returns full details on the layout of a single planetary colony, including links, pins and routes. Note: Planetary information is only recalculated when the colony is viewed through the client. Information will not update until this criteria is met. --- This route is cached for up to 600 seconds # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_characters_character_id_planets_planet_id(character_id, planet_id, async=True)
>>> result = thread.get()
:param async bool
:param int character_id: An EVE character ID (required)
:param int planet_id: Planet id of the target planet (required)
:param str datasource: The server name you would like data from
:param str token: Access token to use if unable to set a header
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: GetCharactersCharacterIdPlanetsPlanetIdOk
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return self.get_characters_character_id_planets_planet_id_with_http_info(character_id, planet_id, **kwargs) # noqa: E501
else:
(data) = self.get_characters_character_id_planets_planet_id_with_http_info(character_id, planet_id, **kwargs) # noqa: E501
return data
def get_characters_character_id_planets_planet_id_with_http_info(self, character_id, planet_id, **kwargs): # noqa: E501
"""Get colony layout # noqa: E501
Returns full details on the layout of a single planetary colony, including links, pins and routes. Note: Planetary information is only recalculated when the colony is viewed through the client. Information will not update until this criteria is met. --- This route is cached for up to 600 seconds # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_characters_character_id_planets_planet_id_with_http_info(character_id, planet_id, async=True)
>>> result = thread.get()
:param async bool
:param int character_id: An EVE character ID (required)
:param int planet_id: Planet id of the target planet (required)
:param str datasource: The server name you would like data from
:param str token: Access token to use if unable to set a header
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: GetCharactersCharacterIdPlanetsPlanetIdOk
If the method is called asynchronously,
returns the request thread.
"""
all_params = ['character_id', 'planet_id', 'datasource', 'token', 'user_agent', 'x_user_agent'] # noqa: E501
all_params.append('async')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method get_characters_character_id_planets_planet_id" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'character_id' is set
if ('character_id' not in params or
params['character_id'] is None):
raise ValueError("Missing the required parameter `character_id` when calling `get_characters_character_id_planets_planet_id`") # noqa: E501
# verify the required parameter 'planet_id' is set
if ('planet_id' not in params or
params['planet_id'] is None):
raise ValueError("Missing the required parameter `planet_id` when calling `get_characters_character_id_planets_planet_id`") # noqa: E501
if 'character_id' in params and params['character_id'] < 1: # noqa: E501
raise ValueError("Invalid value for parameter `character_id` when calling `get_characters_character_id_planets_planet_id`, must be a value greater than or equal to `1`") # noqa: E501
collection_formats = {}
path_params = {}
if 'character_id' in params:
path_params['character_id'] = params['character_id'] # noqa: E501
if 'planet_id' in params:
path_params['planet_id'] = params['planet_id'] # noqa: E501
query_params = []
if 'datasource' in params:
query_params.append(('datasource', params['datasource'])) # noqa: E501
if 'token' in params:
query_params.append(('token', params['token'])) # noqa: E501
if 'user_agent' in params:
query_params.append(('user_agent', params['user_agent'])) # noqa: E501
header_params = {}
if 'x_user_agent' in params:
header_params['X-User-Agent'] = params['x_user_agent'] # noqa: E501
form_params = []
local_var_files = {}
body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501
# Authentication setting
auth_settings = ['evesso'] # noqa: E501
return self.api_client.call_api(
'/v3/characters/{character_id}/planets/{planet_id}/', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='GetCharactersCharacterIdPlanetsPlanetIdOk', # noqa: E501
auth_settings=auth_settings,
async=params.get('async'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
def get_corporations_corporation_id_customs_offices(self, corporation_id, **kwargs): # noqa: E501
"""List corporation customs offices # noqa: E501
List customs offices owned by a corporation --- This route is cached for up to 3600 seconds --- Requires one of the following EVE corporation role(s): Director # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_corporations_corporation_id_customs_offices(corporation_id, async=True)
>>> result = thread.get()
:param async bool
:param int corporation_id: An EVE corporation ID (required)
:param str datasource: The server name you would like data from
:param int page: Which page of results to return
:param str token: Access token to use if unable to set a header
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: list[GetCorporationsCorporationIdCustomsOffices200Ok]
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return self.get_corporations_corporation_id_customs_offices_with_http_info(corporation_id, **kwargs) # noqa: E501
else:
(data) = self.get_corporations_corporation_id_customs_offices_with_http_info(corporation_id, **kwargs) # noqa: E501
return data
def get_corporations_corporation_id_customs_offices_with_http_info(self, corporation_id, **kwargs): # noqa: E501
"""List corporation customs offices # noqa: E501
List customs offices owned by a corporation --- This route is cached for up to 3600 seconds --- Requires one of the following EVE corporation role(s): Director # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_corporations_corporation_id_customs_offices_with_http_info(corporation_id, async=True)
>>> result = thread.get()
:param async bool
:param int corporation_id: An EVE corporation ID (required)
:param str datasource: The server name you would like data from
:param int page: Which page of results to return
:param str token: Access token to use if unable to set a header
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: list[GetCorporationsCorporationIdCustomsOffices200Ok]
If the method is called asynchronously,
returns the request thread.
"""
all_params = ['corporation_id', 'datasource', 'page', 'token', 'user_agent', 'x_user_agent'] # noqa: E501
all_params.append('async')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method get_corporations_corporation_id_customs_offices" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'corporation_id' is set
if ('corporation_id' not in params or
params['corporation_id'] is None):
raise ValueError("Missing the required parameter `corporation_id` when calling `get_corporations_corporation_id_customs_offices`") # noqa: E501
if 'corporation_id' in params and params['corporation_id'] < 1: # noqa: E501
raise ValueError("Invalid value for parameter `corporation_id` when calling `get_corporations_corporation_id_customs_offices`, must be a value greater than or equal to `1`") # noqa: E501
collection_formats = {}
path_params = {}
if 'corporation_id' in params:
path_params['corporation_id'] = params['corporation_id'] # noqa: E501
query_params = []
if 'datasource' in params:
query_params.append(('datasource', params['datasource'])) # noqa: E501
if 'page' in params:
query_params.append(('page', params['page'])) # noqa: E501
if 'token' in params:
query_params.append(('token', params['token'])) # noqa: E501
if 'user_agent' in params:
query_params.append(('user_agent', params['user_agent'])) # noqa: E501
header_params = {}
if 'x_user_agent' in params:
header_params['X-User-Agent'] = params['x_user_agent'] # noqa: E501
form_params = []
local_var_files = {}
body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501
# Authentication setting
auth_settings = ['evesso'] # noqa: E501
return self.api_client.call_api(
'/v1/corporations/{corporation_id}/customs_offices/', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='list[GetCorporationsCorporationIdCustomsOffices200Ok]', # noqa: E501
auth_settings=auth_settings,
async=params.get('async'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
def get_universe_schematics_schematic_id(self, schematic_id, **kwargs): # noqa: E501
"""Get schematic information # noqa: E501
Get information on a planetary factory schematic --- This route is cached for up to 3600 seconds # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_universe_schematics_schematic_id(schematic_id, async=True)
>>> result = thread.get()
:param async bool
:param int schematic_id: A PI schematic ID (required)
:param str datasource: The server name you would like data from
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: GetUniverseSchematicsSchematicIdOk
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return self.get_universe_schematics_schematic_id_with_http_info(schematic_id, **kwargs) # noqa: E501
else:
(data) = self.get_universe_schematics_schematic_id_with_http_info(schematic_id, **kwargs) # noqa: E501
return data
def get_universe_schematics_schematic_id_with_http_info(self, schematic_id, **kwargs): # noqa: E501
"""Get schematic information # noqa: E501
Get information on a planetary factory schematic --- This route is cached for up to 3600 seconds # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_universe_schematics_schematic_id_with_http_info(schematic_id, async=True)
>>> result = thread.get()
:param async bool
:param int schematic_id: A PI schematic ID (required)
:param str datasource: The server name you would like data from
:param str user_agent: Client identifier, takes precedence over headers
:param str x_user_agent: Client identifier, takes precedence over User-Agent
:return: GetUniverseSchematicsSchematicIdOk
If the method is called asynchronously,
returns the request thread.
"""
all_params = ['schematic_id', 'datasource', 'user_agent', 'x_user_agent'] # noqa: E501
all_params.append('async')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method get_universe_schematics_schematic_id" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'schematic_id' is set
if ('schematic_id' not in params or
params['schematic_id'] is None):
raise ValueError("Missing the required parameter `schematic_id` when calling `get_universe_schematics_schematic_id`") # noqa: E501
collection_formats = {}
path_params = {}
if 'schematic_id' in params:
path_params['schematic_id'] = params['schematic_id'] # noqa: E501
query_params = []
if 'datasource' in params:
query_params.append(('datasource', params['datasource'])) # noqa: E501
if 'user_agent' in params:
query_params.append(('user_agent', params['user_agent'])) # noqa: E501
header_params = {}
if 'x_user_agent' in params:
header_params['X-User-Agent'] = params['x_user_agent'] # noqa: E501
form_params = []
local_var_files = {}
body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501
# Authentication setting
auth_settings = [] # noqa: E501
return self.api_client.call_api(
'/v1/universe/schematics/{schematic_id}/', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='GetUniverseSchematicsSchematicIdOk', # noqa: E501
auth_settings=auth_settings,
async=params.get('async'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
|
<gh_stars>100-1000
import pytest
@pytest.fixture(scope="module")
def setup_fpm_fixture(host, request):
print('Backing up current fpm configuration')
host.run("cp /usr/local/etc/php-fpm.d/zz-docker.conf /tmp/zz-docker.conf")
yield 1
print('Recovering fpm configuration and reloading after module')
host.run("cp /tmp/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf")
@pytest.fixture
def setup_fpm_to_default_fixture(host, request, setup_fpm_fixture):
print('Recovering fpm configuration and reloading')
host.run("cp -f /tmp/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf")
host.run("kill -USR2 1")
@pytest.mark.php_fpm
def test_exit_when_no_status_page_is_configured(host, setup_fpm_to_default_fixture):
# disable fpm status page
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/pm.status_path/ s/^;*/;/'")
host.run("kill -USR2 1")
cmd = host.run("php-fpm-healthcheck -v")
assert cmd.rc == 8
assert "Trying to connect to php-fpm via:" in cmd.stdout
assert "status output:" in cmd.stdout
assert "php-fpm status page non reachable" in cmd.stderr
@pytest.mark.php_fpm
def test_fpm_on_socket(host, setup_fpm_to_default_fixture):
# change fpm to socket
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/^listen/ s/.*/listen = \\/var\\/run\\/php-fpm.sock/'")
host.run("kill -USR2 1")
cmd = host.run("FCGI_CONNECT=/var/run/php-fpm.sock php-fpm-healthcheck -v")
assert cmd.rc == 0
assert "Trying to connect to php-fpm via:" in cmd.stdout
assert "status output:" in cmd.stdout
assert "pool:" in cmd.stdout
# https://github.com/renatomefi/php-fpm-healthcheck/issues/18
@pytest.mark.php_fpm
def test_fpm_on_socket_with_huge_env(host, setup_fpm_to_default_fixture):
cmd = host.run("HUGE_ENV=\"$(dd if=/dev/zero bs=8192 count=1 | tr '\\000' '\\040')\" php-fpm-healthcheck -v")
assert cmd.rc == 0
assert "Trying to connect to php-fpm via:" in cmd.stdout
assert "status output:" in cmd.stdout
assert "pool:" in cmd.stdout
@pytest.mark.php_fpm
def test_default_status_page_path(host, setup_fpm_to_default_fixture):
cmd = host.run("php-fpm-healthcheck -v")
assert cmd.rc == 0
assert "Trying to connect to php-fpm via: localhost:9000/status" in cmd.stdout
@pytest.mark.php_fpm
def test_exit_when_fpm_is_invalid_path(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_STATUS_PATH=/invalid php-fpm-healthcheck -v")
assert cmd.rc == 8
assert "Trying to connect to php-fpm via: localhost:9000/invalid" in cmd.stdout
assert "File not found." in cmd.stdout
assert "php-fpm status page non reachable" in cmd.stderr
@pytest.mark.alpine
def test_exit_when_fpm_is_not_reachable_apk(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v")
assert cmd.rc in (111, 9)
assert "Trying to connect to php-fpm via: localhost:9001" in cmd.stdout
@pytest.mark.alpine
def test_exit_when_fpm_is_invalid_host_apk(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=abc php-fpm-healthcheck -v")
assert cmd.rc in (2, 9)
assert "Trying to connect to php-fpm via: abc" in cmd.stdout
@pytest.mark.stretch
def test_exit_when_fpm_is_not_reachable_apt(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v")
assert cmd.rc == 111
assert "Trying to connect to php-fpm via: localhost:9001" in cmd.stdout
@pytest.mark.stretch
def test_exit_when_fpm_is_invalid_host_apt(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=abc php-fpm-healthcheck -v")
assert cmd.rc == 2
assert "Trying to connect to php-fpm via: abc" in cmd.stdout
|
import zborderframe
import zlabel
import zcheckbox
import zlineedit
import zwall
import zutils
class findingbot:
def __init__(self, ignore_case, is_regex, lines, cursor, search_for ):
self.ignore_case = ignore_case
self.is_regex = is_regex
self.text = "\n".join(lines)
cx = cursor[0]
cy = cursor[1]
self.c = 0
y = 0
while y < cy:
self.c += len(lines[y])+1
y+=1
self.c += cx
zutils.debug("Cursor is at "+str(self.c)+"; cursor was "+ str(cursor) + " and is now "+str(self.c_to_cursor(self.c)))
if not is_regex:
self.search_for = search_for.replace("\\n", "\n").replace("\\t","\t").replace("\\r", "\r").replace("\\\\", "\\")
else:
self.search_for = search_for
if ignore_case:
self.text = self.text.lower()
self.search_for = self.search_for.lower()
def c_to_cursor(self, c):
cy = self.text[:c].count("\n")
cx = len(self.text[:c]) - self.text[:c].rfind("\n") - 1
return cx, cy
def find_next(self):
if not self.is_regex:
for run in [0,1]:
a = self.text.find(self.search_for, self.c) if run == 0 else self.text.find(self.search_for, 0, self.c)
if a != -1:
sx, sy = self.c_to_cursor(a)
cx, cy = self.c_to_cursor(a+len(self.search_for))
self.c = a
return cx,cy,sx,sy
zutils.debug("starting from beginning")
return -1,-1,-1,-1
else:
return 0,0,1,0
class zsearchframe(zborderframe.zborderframe):
def __init__(self, parent, pos=(0,0), size=(0,0), documenthandler=None):
txtsearch = "Srch. "
txtrepl = "Repl. "
txtcase = "Match case"
txtregex = "Reg. Expr."
super().__init__(parent, pos, size, "Search and Replace")
self._qlbl = zlabel.zlabel(self, (1,2), (len(txtsearch), 1), txtsearch)
self._qlbl._wants_focus = False
self._qtext = zlineedit.zlineedit(self, (len(txtsearch)+2,2), (self._size[0]-len(txtsearch)-4, 1), "")
self._qtext.on_enter = self._on_enter_search
self.add_child(self._qtext)
self.add_child(self._qlbl)
self._rlbl = zlabel.zlabel(self, (1,3), (len(txtrepl), 1), txtrepl)
self._rlbl._wants_focus = False
self._rtext = zlineedit.zlineedit(self, (len(txtrepl)+2,3), (self._size[0]-len(txtrepl)-4, 1), "")
self._rtext.on_enter = self._on_enter_replace
self.add_child(self._rtext)
self.add_child(self._rlbl)
self._casecb = zcheckbox.zcheckbox(self, (1,5), (len(txtcase)+2, 1), txtcase)
self.add_child(self._casecb)
self._regexcb = zcheckbox.zcheckbox(self, (len(txtcase)+4,5), (len(txtregex)+2, 1), txtregex)
self.add_child(self._regexcb)
self._documenthandler = documenthandler
def _on_enter_search(self, sender):
doc = self._documenthandler.get_current_doc()
txt = self._qtext.get_text()
so = findingbot( not self._casecb.is_checked(), self._regexcb.is_checked(), doc.get_lines(), doc.get_cursor(), txt)
x1,y1,x2,y2 = so.find_next()
if x1 != -1 and y1 != -1 and x2 != -1 and y2 != -1:
doc.set_cursor(x1,y1)
doc.set_sel(x2,y2)
else:
zutils.debug("not found :(")
def _on_enter_replace(self, sender):
pass
def get_text(self):
return self._text.get_text()
def do_paint(self, wall):
self.clear_wall(wall)
super().do_paint(wall)
def on_key(self, key, char):
if key == zutils.KEY_UP:
self.next_focus(True)
elif key == zutils.KEY_DOWN:
self.next_focus(False)
else:
super().on_key(key, char) |
import sqlite3
import requests
import time
import json
from bs4 import BeautifulSoup
import regex
from helper_class.chrome_driver import create_driver, quit_driver
from helper_class.country_names import find_all_iso
from helper_class.wiki_visa_parser import wiki_visa_parser
from lib.database import Database
from helper_class.flags import Flags
from helper_class.logger import Logger
# Initialize flags, logger & database
FLAGS = Flags()
LEVEL = FLAGS.get_logger_level()
LOGGER = Logger(level=LEVEL) if LEVEL is not None else Logger()
def get_name_and_advisory_of_countries():
try:
#this is the link to the first page
url = 'https://travel.state.gov/content/travel/en/traveladvisories/traveladvisories.html/'
LOGGER.info("Retrieving URL of all countries for United States")
#set up the headless chrome driver
driver = create_driver()
driver.get(url)
#Selenium hands the page source to Beautiful Soup
soup=BeautifulSoup(driver.page_source, 'lxml')
#pattern of the link to the country page that the href should match
table = soup.find('table')
table_body = table.find('tbody')
table_rows = table_body.find_all('tr')
counter = 0
info = {}
for tr in table_rows:
if(counter != 0):
cols = tr.find_all('td')
href = cols[0].find('a').get('href')# gets url for each country that is needed for additional advisory info
link = "https://travel.state.gov/{}".format(href,sep='')
cols = [ele.text.strip() for ele in cols]
nameLength = len(cols[0])-16
name = cols[0][0:nameLength]
if(name != 'W'):
advisory = cols[1]
advisory += '</br>'+parse_a_country_additional_advisory_info(link,driver)
info[name] = advisory
counter += 1
finally:
driver.close()
driver.quit()
return info
#Retrieves all the tooltips which contain additional advisory info
def parse_a_country_additional_advisory_info(url, driver):
driver.get(url)
#Selenium hands the page source to Beautiful Soup
soup=BeautifulSoup(driver.page_source, 'lxml')
warning = "<ul> "
div_id = soup.find("div", {"id": "container tooltipalert"})
a_tags = div_id.find_all('a')
for a in a_tags:
listToStr = ' '.join(map(str, a.get('class')))
if(listToStr == 'showThreat'): #if tooltip is marked as showThreat then this country is marked as having this threat
if(a.get('title')!='Tool Tip: Other'):
tooltip = a.get('data-tooltip').rstrip("\n")
index = tooltip.index(':')
tooltip = tooltip[0 : index]+ '</b>' + tooltip[index: ]
warning += '<li><b>'+ tooltip
return warning + '</ul>'
def save_to_united_states():
LOGGER.info("Begin parsing and saving for United States table...")
driver = create_driver()
data = {} #Used to store of all the parsed data of each country
name_to_advisories ={} #Stores the names and associated advisories
LOGGER.info(f'Retrieving visa requirements for all countries for the United States advisory')
name_advisory = get_name_and_advisory_of_countries()
wiki_visa_url = "https://en.wikipedia.org/wiki/Visa_requirements_for_United_States_citizens"
wiki_visa_ob = wiki_visa_parser(wiki_visa_url,driver)
visas = wiki_visa_ob.visa_parser_table()
LOGGER.success('Successfully retrieved visa requirements for all countries for the United States advisory')
for name in sorted (name_advisory.keys()): #Sorts the dictionary containing names and advisories
name_to_advisories[name] = name_advisory[name]
counter_country = 0
for country in name_to_advisories: #iterates through name_to_advisories to retrieve advisories
driver.implicitly_wait(5)
name = country
advisory = name_to_advisories[country]
visa_text= ""
for countryVisa in visas: # iterates through list of visas to retrieve visas
if(countryVisa == country):
visa_text = visas[countryVisa].get('visa')
del visas[countryVisa]
break;
country_iso = "na"
data[name] = {'country-iso':country_iso,'name':name,'advisory-text':advisory,'visa-info':visa_text}
if ((counter_country%50) == 0):
quit_driver(driver)
driver = create_driver()
counter_country += 1
data = find_all_iso(data)#Sets iso for each country
with open('./advisory-us.json', 'w') as outfile:
json.dump(data, outfile)
save_into_db(data)
def save_into_db(data):
# create an an sqlite_advisory object
db = Database("countries.sqlite")
db.drop_table("US")
db.add_table("US", country_iso="text", name="text", advisory_text="text", visa_info="text")
LOGGER.info('Saving United State table into the database')
try:
for country in data:
iso = data[country].get('country-iso')
name = data[country].get('name')
advisory = data[country].get('advisory-text')
visa = data[country].get('visa-info')
LOGGER.info(f"Saving {name} into the US table")
db.insert("US",iso,name,advisory,visa)
LOGGER.info(f"{name} was succesfully saved into the US table with the following information: {visa}. {advisory}")
LOGGER.success('US table has been successfully saved into the databse')
except Exception as error_msg:
LOGGER.error(f'Error has occured while saving the countries into the US table because of the following error: {error_msg}')
db.close_connection()
#save_to_united_states() |
<gh_stars>1-10
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016-2018
# Author: <NAME> (<EMAIL>)
# file: io_gml_format.py
"""
Reading and writing graphs in LEDA format (.gw, .lgr).
The Library of Efficient Data types and Algorithms (LEDA) is a propitiatory
licensed software library providing C++ implementations of a broad variety of
algorithms for graph theory and computational geometry.
Specifications:
http://www.algorithmic-solutions.info/leda_guide/graphs/leda_native_graph_fileformat.html
Example:
#header section
LEDA.GRAPH
string
int
-1
#nodes section
5
|{v1}|
|{v2}|
|{v3}|
|{v4}|
|{v5}|
#edges section
7
1 2 0 |{4}|
1 3 0 |{3}|
2 3 0 |{2}|
3 4 0 |{3}|
3 5 0 |{7}|
4 5 0 |{6}|
5 1 0 |{1}|
The LEDA graph format is a simple and a fast format always separated in a
header, nodes and edges section. The header always starts with LEDA.GRAPH
followed by the data type for node and edge data as string, int, float or
boolean or 'void' if no data defined. The fourth line described directionality
of the graph as directed (-1) or undirected (-2).
The nodes section starts with the number of nodes followed by an ordered list
of node labels (between |{}|) that are sequentially number starting from 1.
The node labels are converted to the respective types as indicated in the
header section.
The edge section is similar to nodes but list for each edge the source and
target nodes following the sequential number of the nodes, reversal number
(not used) and edge data label (between |{}|).
"""
import logging
from graphit import __module__, Graph
from graphit.graph_exceptions import GraphitException
from graphit.graph_py2to3 import StringIO
from graphit.graph_io.io_helpers import open_anything
logger = logging.getLogger(__module__)
data_types = {'string': str, 'int': int, 'bool': bool, 'float': float}
__all__ = ['read_lgr', 'write_lgr']
def read_lgr(lgr, graph=None, edge_label='label'):
"""
Read graph in LEDA format
Nodes are added to the graph using a unique ID or with the node data
as label depending if the graph.data.auto_nid is True or False.
Edge data is added to the edge attributes using `edge_label` as key.
The data types for both nodes and edges is set according to the
specifications in the LEDA header as either string, int, float or bool.
:param lgr: LEDA graph data.
:type lgr: File, string, stream or URL
:param graph: Graph object to import LEDA data in
:type graph: :graphit:Graph
:param edge_label: edge data label name
:type edge_label: :py:str
:return: Graph object
:rtype: :graphit:Graph
:raises: TypeError if node/edge type conversion failed
GraphitException in case of malformed LEDA file
"""
# User defined or default Graph object
if graph is None:
graph = Graph()
elif not isinstance(graph, Graph):
raise GraphitException('Unsupported graph type {0}'.format(type(graph)))
# Parse LEDA file
lgr_file = open_anything(lgr)
header = []
nodes = []
edges = []
container = header
for line in lgr_file.readlines():
line = line.strip()
if line:
if line.startswith('#header'):
container = header
continue
if line.startswith('#nodes'):
container = nodes
continue
if line.startswith('#edges'):
container = edges
continue
container.append(line)
# Parse LEDA header
if not header[0] == 'LEDA.GRAPH':
raise GraphitException('File is not a valid LEDA graph format')
# Node and edge data types and graph directionality
node_type = data_types.get(header[1])
edge_type = data_types.get(header[2])
graph.directed = int(header[3]) == -1
# Parse LEDA nodes
node_mapping = {}
for i, node in enumerate(nodes[1:], start=1):
data = node.strip('|{}|') or None
if node_type and data:
data = node_type(data)
nid = graph.add_node(data)
node_mapping[i] = nid
# Parse LEDA edges
for edge in edges[1:]:
try:
source, target, reversal, label = edge.split()
except ValueError:
raise GraphitException('Too few fields in LEDA edge {0}'.format(edge))
attr = {edge_label: label.strip('|{}|') or None}
if edge_type and attr[edge_label]:
attr[edge_label] = edge_type(attr[edge_label])
graph.add_edge(node_mapping[int(source)], node_mapping[int(target)], **attr)
return graph
def write_lgr(graph, node_key=None, edge_key=None, node_data_type='string', edge_data_type='void'):
"""
Export a graph to an LGR data format
The LEDA format allows for export of only one node or edge data type
(as: |{data type}|). For nodes this is usually the node label and for
edges any arbitrary data key,value pair. In both cases the data type
is required to be of either: string, int, float or bool.
Nodes and edges are exported by iterating over them using `iternodes`
and `iteredges`. Iteration uses the graphit Object Relations Mapper (ORM)
allowing full control over the data export by overriding the `get`
method globally in the 'NodeTools' or 'EdgeTools' classes or using custom
classes registered with the ORM.
Data returned by the `get` method will be serialized regardless the return
type.
The node and edge data types are registered globally in the LENA file using
`node_data_type` and `edge_data_type` set to 'void' (no data) by default.
:param graph: Graph to export
:type graph: :graphit:Graph
:param node_key: key name of node data to export
:type node_key: :py:str
:param edge_key: key name of edge data to export
:type edge_key: :py:str
:param node_data_type: primitive data type of exported node data
:type node_data_type: :py:str
:param edge_data_type: primitive data type of exported edge data
:type edge_data_type: :py:str
:return: Graph exported as LGR format
:rtype: :py:str
:raises: GraphitException
"""
# Default node_key to graph.data.key_tag
if node_key is None:
node_key = graph.data.key_tag
# If export of node/edge data corresponding data types need to be defined
if (node_key is not None and node_data_type == 'void') or (edge_key is not None and edge_data_type == 'void'):
raise GraphitException('Define node_data_type and/or edge_data_type')
# Create empty file buffer
string_buffer = StringIO()
# Print header
string_buffer.write('#header section\nLEDA.GRAPH\n{0}\n{1}\n'.format(node_data_type, edge_data_type))
string_buffer.write('{0}\n'.format(-1 if graph.directed else -2))
# Print nodes
string_buffer.write('#nodes section\n{0}\n'.format(len(graph.nodes)))
node_mapping = {}
for i, node in enumerate(graph.iternodes(), start=1):
string_buffer.write('|{{{0}}}|\n'.format(str(node.get(node_key, default=''))))
node_mapping[node.nid] = i
# Print edges
string_buffer.write('#edges section\n{0}\n'.format(len(graph.edges)))
for edge in graph.iteredges():
source, target = edge.nid
string_buffer.write('{0} {1} 0 |{{{2}}}|\n'.format(node_mapping[source], node_mapping[target],
str(edge.get(edge_key, default=''))))
logger.info('Graph {0} exported in LEDA format'.format(repr(graph)))
# Reset buffer cursor
string_buffer.seek(0)
return string_buffer.read()
|
"""
playing around with fbprophet
"""
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from fbprophet import Prophet
from scipy.stats import boxcox
from scipy.special import inv_boxcox
from rich import print
columns = ["created_at", "id"]
tic = dt.datetime.now()
_df = pd.read_csv("../cleo_example/data/cleo_users.csv", usecols=columns, low_memory=False)
print(f"""time to read csv: {str(dt.datetime.now() - tic)}\n
shape: {_df.shape}
""")
_df_tidy = _df.copy()
_df_tidy = _df_tidy.drop_duplicates(keep='last')
_df_tidy["date"] = pd.to_datetime(_df_tidy.created_at, format='%Y-%m-%d')
assert _df_tidy.id.nunique() == _df_tidy.shape[0]
df = _df_tidy.groupby("date").agg(
daily_sign_ups=("id", "nunique")
).reset_index()
df.sort_values(by="date", inplace=True)
# df.set_index('date', inplace=True)
# df.sort_index(inplace=True)
print(f"working dataset for prohpet:\n{df.head()}\n")
def plot_line(df: pd.DataFrame, x_axis: str, line: str, c: str = "b"):
x = df[x_axis]
line = df[line]
fig = plt.figure(dpi=100, figsize=(6, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.yaxis.grid()
ax.plot(x, line, color=c)
title = line.replace("_", " ")
ax.set_title(f"{title}")
ax.set_ylabel(f"{line}")
ax.set_xlabel(f"{x}")
# ax.set_xticklabels(x, rotation=-40)
plt.show();
return
##
plot_line(df, df.columns[0], df.columns[1])
"""
box-Cox transforms are data transformations that evaluate a set of lambda coefficients (λ)
and selects the value that achieves the best approximation of normality
the boxcox method returns a positive dataset transformed by a Box-Cox power transformation
the boxcox method has one required input: a 1-dimensional array of positive data to transform
you can also specify the λ value you’d like to use for your transformation (e.g. λ = 0 for a log transform)
otherwise, the boxcox method will find the λ that maximizes the log-likelihood function
and will return it as the second output argument
"""
# Apply Box-Cox Transform to value column and assign to new column y
df['y'], lam = boxcox(df.daily_sign_ups)
plot_line(df, "date", "y", "green")
# instantiating (create an instance of) a Prophet object
m = Prophet()
# must be ds not date
df.rename(columns={"date": "ds"}, inplace=True)
m.fit(df[["ds", "y"]])
"""
Prophet will create a new dataframe assigned to the forecast variable
that contains the forecasted values for future dates under the column yhat,
as well as uncertainty intervals and components for the forecast.
"""
future = m.make_future_dataframe(periods=183)
forecast = m.predict(future)
print(f"\nplotting fbprobhet forecast for 6 months\n")
m.plot(forecast)
print(f"\nplotting fbprobhet components for 6 months\n")
m.plot_components(forecast)
"""
since Prophet was used on the Box-Cox transformed data,
you'll need to transform your forecasted values back to their original units
the inv_boxcox method has two required inputs;
an array of data to transform
a λ value for the transform
we have the λ value from in the "lam variable" from our Box-Cox transformation
"""
# transformaing forecasted values back to their original units
forecast[['yhat','yhat_upper','yhat_lower']] = forecast[['yhat','yhat_upper','yhat_lower']].apply(lambda x: inv_boxcox(x, lam))
print(f"\nplotting fbprobhet forecast for 6 months in original units\n")
m.plot(forecast)
|
<reponame>Delay-Xili/F-Clip<filename>FClip/models/__init__.py
# flake8: noqa
from .hourglass_pose import hg
from .pose_hrnet import get_pose_net as hr
from .hourglass_line import hg as hgl
from FClip.config import M
import torch.nn as nn
import torch
# from torchvision.ops.deform_conv import DeformConv2d
class LineHead(nn.Module):
def __init__(self, input_channels, m, output_channels):
super(LineHead, self).__init__()
ks = M.line_kernel
self.branch1 = nn.Sequential(
nn.Conv2d(input_channels, m, kernel_size=(1, ks), padding=(0, int(ks/2))),
nn.ReLU(inplace=True),
nn.Conv2d(m, output_channels, kernel_size=(1, ks), padding=(0, int(ks/2))),
)
self.branch2 = nn.Sequential(
nn.Conv2d(input_channels, m, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(m, output_channels, kernel_size=1),
)
self.branch3 = nn.Sequential(
nn.Conv2d(input_channels, m, kernel_size=(ks, 1), padding=(int(ks/2), 0)),
nn.ReLU(inplace=True),
nn.Conv2d(m, output_channels, kernel_size=(ks, 1), padding=(int(ks/2), 0)),
)
self.merge = nn.Conv2d(int(3 * output_channels), output_channels, kernel_size=1)
def forward(self, x):
x1 = self.branch1(x)
x2 = self.branch2(x)
x3 = self.branch3(x)
x4 = torch.cat([x1, x2, x3], dim=1)
return self.merge(x4)
class LCNNHead(nn.Module):
def __init__(self, input_channels, num_class, head_size=[[2], [2], [1]]):
super(LCNNHead, self).__init__()
m = int(input_channels / 4)
heads = []
for output_channels in sum(head_size, []):
heads.append(
nn.Sequential(
nn.Conv2d(input_channels, m, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(m, output_channels, kernel_size=1),
)
)
self.heads = nn.ModuleList(heads)
assert num_class == sum(sum(head_size, []))
def forward(self, x):
return torch.cat([head(x) for head in self.heads], dim=1)
class MultitaskHead(nn.Module):
def __init__(self, input_channels, num_class):
super(MultitaskHead, self).__init__()
m = int(input_channels / 4)
heads = []
heads_size = sum(self._get_head_size(), [])
heads_net = M.head_net
for k, (output_channels, net) in enumerate(zip(heads_size, heads_net)):
if net == "raw":
heads.append(
nn.Sequential(
nn.Conv2d(input_channels, m, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(m, output_channels, kernel_size=1),
)
)
print(f"{k}-th head, head type {net}, head output {output_channels}")
elif net == "raw_upsampler":
heads.append(
nn.Sequential(
nn.UpsamplingBilinear2d(size=(M.resolution, M.resolution)),
nn.Conv2d(input_channels, m, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(m, output_channels, kernel_size=1),
)
)
print(f"{k}-th head, head type {net}, head output {output_channels}")
elif net == "mask":
heads.append(
nn.Sequential(
nn.Conv2d(input_channels, 256, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(256, m, kernel_size=3, padding=1),
# nn.BatchNorm2d(m),
nn.ReLU(inplace=True),
nn.Conv2d(m, output_channels, kernel_size=1),
)
)
print(f"{k}-th head, head type {net}, head output {output_channels}")
elif net == "line":
heads.append(
LineHead(input_channels, m, output_channels)
)
print(f"{k}-th head, head type {net}, head output {output_channels}")
else:
raise NotImplementedError
self.heads = nn.ModuleList(heads)
assert num_class == sum(sum(self._get_head_size(), []))
@staticmethod
def _get_head_size():
M_dic = M.to_dict()
head_size = []
for h in M_dic['head']['order']:
head_size.append([M_dic['head'][h]['head_size']])
return head_size
def forward(self, x):
return torch.cat([head(x) for head in self.heads], dim=1)
|
<gh_stars>0
"""
CANNR TM analytics container building tool example showing Python function that
decides whether someone can be scheduled for a hypothetical vaccine for a
hypothetical disease, based on risk factors.
Copyright 2021 <NAME> <EMAIL>
All rights reserved
Maintainer <NAME> <EMAIL>
"""
import numpy
import math
# Cutoff for deciding that predicted mortality qualifies someone for the vaccine.
mortCutoff = 0.10
# Cutoff for deciding that predicted lost years of life qualifies someone for the vaccine.
yearsCutoff = 5
# Coefficients of a hypothetical logistic regression model for P(Death|Risk Factors)
mortCoefs = numpy.array([
-8.68233, # Constant
0.08878, # Age
1.23936, # Hypertension
0.35158, # Cardio
1.21281, # Pulmonary
1.86774, # Diabetes
2.12715]) # Obesity
# Coefficients of a hypothetical model for expected life years remaining for someone based on their risk factors.
# Model uses a logistic function to predict expected years of life as a fraction of years left to age 100.
yearsCoefs = numpy.array([
0.940725, # Constant
0.001434, # Age
-0.661604, # Hypertension
-1.012414, # Cardio
-1.71273, # Pulmonary
-0.843038, # Diabetes
-0.696056]) # Obesity
# Logistic function
def logistic(x):
return math.exp(x)/(1+math.exp(x))
# Returns the predicted value from the logistic model, given the predictors (xPreds) and model parameters (params).
def logistModel(xPreds, params):
return logistic(numpy.dot(xPreds, params))
# Model for mortality from the disease, given the person is infected.
def mortModel(xPreds):
age = xPreds[0]
if age >= 100 or age <= 0:
return 0.0
else:
return logistModel(numpy.append([1], xPreds), mortCoefs)
# Hypothetical model for remaining years of life, given the person's age and other risk factors.
def yearsModel(xPreds):
age = xPreds[0]
if age >= 100 or age <= 0:
return 0.0
else:
return (100 - age)*logistModel(numpy.append([1], xPreds), yearsCoefs)
# Decides whether someone should get the vaccine, based on their risk factors:
# age - The person's age in years
# hypertension - Boolean indicating hypertension
# cardio - Boolean indicating cardiovascular disease like arteriosclerosis
# pulmonary - Boolean indicating pulmonary disease like COPD or asthma
# diabetes - Boolean indicating diabetes
# obesity - Boolean indicating obesity defined by a BMI of at least 30.0
#
# In addition, the boolean flag years indicates whether the decision should be
# made based on predicted lost life years (True), or just mortality (False).
# To be exposed as a service.
def vaxDecision(inputDict):
# Convert the risk factors into an array (list).
xPreds = [
inputDict.get('age', 0.0),
int(inputDict.get('hypertension', False)),
int(inputDict.get('cardio', False)),
int(inputDict.get('pulmonary', False)),
int(inputDict.get('diabetes', False)),
int(inputDict.get('obesity', False))
]
# If decision is to be based on life years, calculate predicted life years
# lost and check whether greater than cutoff.
if inputDict.get('years', False):
return mortModel(xPreds)*yearsModel(xPreds) >= yearsCutoff
# Otherwise, just use mortality.
else:
return mortModel(xPreds) >= mortCutoff
# Sample input for vaxDecision.
# To be exposed as a service.
def sampleInput():
return {
'age': 50,
'hypertension': False,
'cardio': False,
'pulmonary': False,
'diabetes': True,
'obesity': True,
'years': True
}
xPreds = [50, 0, 0, 0, 1, 1]
print(mortModel(xPreds))
print(yearsModel(xPreds))
print(mortModel(xPreds)*yearsModel(xPreds))
print(vaxDecision(sampleInput()))
|
<gh_stars>0
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ecl.compute.v2 import availability_zone as _availability_zone
from ecl.compute.v2 import extension
from ecl.compute.v2 import flavor as _flavor
from ecl.compute.v2 import image as _image
from ecl.compute.v2 import keypair as _keypair
from ecl.compute.v2 import limits
from ecl.compute.v2 import server as _server
from ecl.compute.v2 import server_action as _server_action
from ecl.compute.v2 import server_interface as _server_interface
from ecl.compute.v2 import server_volume as _server_volume
from ecl.compute.v2 import quota as _quota
from ecl.compute.v2 import volume as _volume
from ecl import proxy2
from ecl import resource2
class Proxy(proxy2.BaseProxy):
def servers(self, details=True, **query):
"""Retrieve a list of servers
:param bool details: When set to ``False``
:class:`~ecl.compute.v2.server.Server` instances
will be returned. The default, ``True``, will cause
:class:`~ecl.compute.v2.server.ServerDetail`
instances to be returned.
:param kwargs \*\*query: Optional query parameters to be sent to limit
the servers being returned. Available parameters include:
* changes_since: A time/date stamp for when the server last changed status.
* image: An image resource or ID.
* flavor: A flavor resource or ID.
* name: Name of the server as a string.
* status: Value of the status of the server so that you can filter on "ACTIVE" for example.
* host: Name of the host as a string.
* limit: Requests a specified page size of returned items from the query.
* marker: Specifies the ID of the last-seen item.
:returns: A list of :class:`~ecl.compute.v2.server.Server`
"""
srv = _server.ServerDetail if details else _server.Server
return list(self._list(srv, paginated=True, **query))
def create_server(self, flavor_id, name, disk_config=None, image_id=None,
min_count=None, max_count=None, availability_zone=None,
config_drive=None, key_name=None, user_data=None,
block_device_mapping=None, block_device_mapping_v2=None,
metadata=None, networks=None, personality=None, admin_pass=None, **attrs):
"""Create a new server from attributes
:param string flavor_id: ID of server
:param string name: Name of server
:param dict disk_config: a single partition which is expanded
to the size of the flavor selected
:param string image_id: if block_device_mapping_v2 is not specified,
it is require
:param int min_count: minim count of instance
:param int max_count: maxmum count of instance
:param string availability_zone: availability zone
:param boolean config_drive: Enables metadata injection in a server
through a configuration drive
:param string key_name: key name
:param string (Base64 encoded) user_data: user data
:param array block_device_mapping: block device mapping info
:param array block_device_mapping_v2: block device mapping v2 info
:param dict metadata: metadata of the server
:param array networks: if a tenant has more than two networks, it is required
:param array personality: This param will not run for ECL2.0
:param string admin_pass: the administrator password for the server
:param kwargs attrs: Keyword arguments which will be used to create
a :class:`~ecl.compute.v2.server.Server`,
comprised of the properties on the Server class.
:returns: :class:`~ecl.compute.v2.server.Server`
"""
attrs.update({"flavor_id": flavor_id})
attrs.update({"name": name})
if disk_config is not None:
attrs.update({"disk_config": disk_config})
if image_id is not None:
attrs.update({"image_id": image_id})
if min_count:
attrs.update({"min_count": min_count})
if max_count:
attrs.update({"max_count": max_count})
if availability_zone:
attrs.update({"availability_zone": availability_zone})
if config_drive:
attrs.update({"config_drive": config_drive})
if key_name:
attrs.update({"key_name": key_name})
if user_data:
attrs.update({"user_data": user_data})
if block_device_mapping:
attrs.update({"block_device_mapping": block_device_mapping})
if block_device_mapping_v2:
attrs.update({"block_device_mapping_v2": block_device_mapping_v2})
if metadata:
attrs.update({"metadata": metadata})
if networks:
attrs.update({"networks": networks})
if personality:
attrs.update({"personality": personality})
if admin_pass:
attrs.update({"admin_pass": admin_pass})
return self._create(_server.Server, **attrs)
def delete_server(self, server, ignore_missing=False, force=False):
"""Delete a server
:param server: The value can be either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the server does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent server
:param bool force: When set to ``True``, the server deletion will be
forced immediatly.
:returns: ``None``
"""
if force:
server = self._get_resource(_server.Server, server)
server.force_delete(self.session)
else:
self._delete(_server.Server, server, ignore_missing=ignore_missing)
def find_server(self, name_or_id, ignore_missing=False):
"""Find a single server
:param string name_or_id: The name or ID of a server.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: :class:`~ecl.compute.v2.server.Server` or None
"""
return self._find(_server.Server, name_or_id,
ignore_missing=ignore_missing)
def get_server(self, server):
"""Get a single server
:param server: The value can be the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:returns: :class:`~ecl.compute.v2.server.Server`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_server.Server, server)
def update_server(self, server, **body):
"""Update a server
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:param string name: Server name
:param string access_ipv4: IPv4 address
:param string access_ipv6: IPv6 address
:returns: :class:`~ecl.compute.v2.server.Server`
"""
return self._update(_server.Server, server, **body)
def wait_for_server(self, server, status='ACTIVE', failures=['ERROR'],
interval=2, wait=120):
"""Not supported
"""
return resource2.wait_for_status(self.session, server, status,
failures, interval, wait)
def create_image_from_server(self, server, name, metadata=None):
"""Create image from a certain server
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:param string name: Image name (1-255 characters).
:param dict metadata: Image metadata ({"metadata_key": "metadata_value"})
:returns: ``None``
"""
virtual_server = self.get_server(server)
return virtual_server.create_image(self.session, name, metadata)
def get_server_console(self, server, vnc_type):
"""Get the console link of server
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:param vnc_type: should be one of these: novnc, rdp-html5, spice-html5, serial
:return: console link and type info
:rtype: :class:`~dict {"url": "", "type": ""}`
"""
virtual_server = self.get_server(server)
return virtual_server.get_console(self.session, vnc_type)
def start_server(self, server):
"""Start the server
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:return: <Response 202>
"""
virtual_server = self.get_server(server)
return virtual_server.start(self.session)
def stop_server(self, server):
"""Stop the server
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:return: <Response 202>
"""
virtual_server = self.get_server(server)
return virtual_server.stop(self.session)
def resize_server(self, server, flavor_id):
"""Resize the server to flavor reference
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance.
:param string flavor_id: ID of flavor to resize
:return: <Response 202>
"""
virtual_server = self.get_server(server)
return virtual_server.resize(self.session, flavor_id)
def get_server_metadata(self, server):
"""Return a dictionary of metadata for a server
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` or
:class:`~ecl.compute.v2.server.ServerDetail`
instance.
:returns: A :class:`~ecl.compute.v2.server.Server` with only the
server's metadata. All keys and values are Unicode text.
"""
res = self.get_server(server)
metadata = res.get_metadata(self.session)
result = _server.Server.existing(id=res.id, metadata=metadata)
return result
def set_server_metadata(self, server, **metadata):
"""Update metadata for a server
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` or
:class:`~ecl.compute.v2.server.ServerDetail`
instance.
:param kwargs metadata: Key/value pairs to be updated in the server's
metadata. No other metadata is modified
by this call. All keys and values are stored
as Unicode.
:returns: A :class:`~ecl.compute.v2.server.Server` with only the
server's metadata. All keys and values are Unicode text.
"""
res = self.get_server(server)
metadata = res.set_metadata(self.session, **metadata)
result = _server.Server.existing(id=res.id, metadata=metadata)
return result
def delete_server_metadata(self, server, keys):
"""Delete metadata for a server
Note: This method will do a HTTP DELETE request for every key in keys.
:param server: Either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` or
:class:`~ecl.compute.v2.server.ServerDetail`
instance.
:param array keys: The keys to delete
:returns: ``None``
"""
res = self.get_server(server)
return res.delete_metadata(self.session, keys)
def create_server_interface(self, server, net_id=None, ip_address=None,
port_id=None, fixed_ips=None):
"""Create a new server interface from attributes
:param server: The server can be either the ID of a server or a
:class:`~ecl.compute.v2.server.Server` instance
that the interface belongs to.
:param string net_id: ID of network, may need to specify ip address
if
:param string ip_address: ip_address of add interface to the VM instance
:param string port_id: ID of port of add interface to the VM instance
:param dict fixed_ips: dict of fixed ips to add to the VM instance
:returns: :class:`~ecl.compute.v2.server_interface.ServerInterface`
"""
attrs = {}
if net_id is not None:
attrs.update({"net_id": net_id})
if ip_address is not None:
attrs.update({
"fixed_ips": {
"ip_address": ip_address
}
})
if port_id is not None:
attrs.update({"port_id": port_id})
if fixed_ips is not None:
attrs.update({"fixed_ips": fixed_ips})
server_id = resource2.Resource._get_id(server)
return self._create(_server_interface.ServerInterface,
server_id=server_id, **attrs)
def delete_server_interface(self, server_interface, server=None,
ignore_missing=False):
"""Delete a server interface
:param server_interface:
The value can be either the ID of a server interface or a
:class:`~ecl.compute.v2.server_interface.ServerInterface`
instance.
:param server: This parameter need to be specified when ServerInterface
ID is given as value. It can be either the ID of a
server or a :class:`~ecl.compute.v2.server.Server`
instance that the interface belongs to.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the server interface does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent server interface.
:returns: ``None``
"""
server_id = self._get_uri_attribute(server_interface, server,
"server_id")
server_interface = resource2.Resource._get_id(server_interface)
self._delete(_server_interface.ServerInterface,
port_id=server_interface,
server_id=server_id,
ignore_missing=ignore_missing)
def server_interfaces(self, server):
"""Return a list of server interfaces
:param server: The server can be either the ID of a server or a
:class:`~ecl.compute.v2.server.Server`.
:returns: A list of
:class:`~ecl.compute.v2.server_interface.ServerInterface`
"""
server_id = resource2.Resource._get_id(server)
return list(self._list(_server_interface.ServerInterface,
paginated=False,
server_id=server_id))
def server_actions(self, server):
"""Return a list of server actions
:param server: The server can be either the ID of a server or a
:class:`~ecl.compute.v2.server.Server`.
:returns: A list of :class:`~ecl.compute.v2.server_action.ServerAction`
"""
server_id = resource2.Resource._get_id(server)
return list(self._list(_server_action.ServerAction, paginated=False,
instance_uuid=server_id))
def get_server_action(self, server_action, server=None):
"""Get a single server action
:param server_action:
The value can be the request ID of a server action or a
:class:`~ecl.compute.v2.server_action.ServerAction`
instance.
:param server: This parameter need to be specified when ServerAction
ID is given as value. It can be either the ID of a
server or a :class:`~ecl.compute.v2.server.Server`
instance that the action belongs to.
:returns: Server Action object
:class:`~ecl.compute.v2.server_action.ServerAction`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
server = self.get_server(server)
action = resource2.Resource._get_id(server_action)
return self._get(_server_action.ServerAction, action,
instance_uuid=server.id, )
def server_volumes(self, server):
"""Return a list of server volumes
:param server: The server can be either the ID of a server or a
:class:`~ecl.compute.v2.server.Server`.
:returns: A list of :class:`~ecl.compute.v2.server_volume.ServerVolume`
"""
server_id = resource2.Resource._get_id(server)
return list(self._list(_server_volume.ServerVolume, paginated=False,
serverId=server_id))
def create_server_volume(self, server, volume_id, device=None):
"""Attaches a volume to the specified server
:param server: The server can be either the ID of a server or a
:class:`~ecl.compute.v2.server.Server`
:param string volume_id: Volume ID to be attached
:param string device: Device name that satisfies the following
conditions: ^/dev/x{0,1}[a-z]{0,1}d{0,1})([a-z]+)[0-9]*$
"""
attrs = {
"volumeId": volume_id
}
if device:
attrs.update({"device": device})
server_id = resource2.Resource._get_id(server)
return self._create(_server_volume.ServerVolume,
serverId=server_id, **attrs)
def delete_server_volume(self, server_volume, server=None,
ignore_missing=False):
"""Detach a volume from a server
:param server_volume:
The value can be either the ID of a server volume or a
:class:`~ecl.compute.v2.server_volume.ServerVolume`
instance.
:param server: This parameter need to be specified when ServerVolume
ID is given as value. It can be either the ID of a
server or a :class:`~ecl.compute.v2.server.Server`
instance that the volume belongs to.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the server volume does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent server volume.
:returns: ``None``
"""
server_id = self._get_uri_attribute(server_volume, server,
"server_id")
attachment = resource2.Resource._get_id(server_volume)
self._delete(_server_volume.ServerVolume,
id=attachment,
serverId=server_id,
ignore_missing=ignore_missing)
def extensions(self):
"""Retrieve a list of extensions
:returns: A list of :class:`~ecl.compute.v2.extension.Extension`.
"""
return list(self._list(extension.Extension, paginated=False))
def find_flavor(self, name_or_id, ignore_missing=False):
"""Find a single flavor
:param string name_or_id: The name or ID of a flavor.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: :class:`~ecl.compute.v2.flavor.Flavor` or None
"""
return self._find(_flavor.Flavor, name_or_id,
ignore_missing=ignore_missing)
def get_flavor(self, flavor):
"""Get a single flavor
:param flavor: The value can be the ID of a flavor or a
:class:`~ecl.compute.v2.flavor.Flavor` instance.
:returns: :class:`~ecl.compute.v2.flavor.Flavor`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_flavor.Flavor, flavor)
def flavors(self, details=True):
"""Return a list of flavors
:param bool details: When ``True``, returns
:class:`~ecl.compute.v2.flavor.FlavorDetail` objects,
otherwise :class:`~ecl.compute.v2.flavor.Flavor`.
:returns: A list of :class:`~ecl.compute.v2.flavor.Flavor`
"""
flv = _flavor.FlavorDetail if details else _flavor.Flavor
return list(self._list(flv, paginated=True))
def delete_image(self, image, ignore_missing=False):
"""Delete an image
:param image: The value can be either the ID of an image or a
:class:`~ecl.compute.v2.image.Image` instance.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the image does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent image.
:returns: ``None``
"""
self._delete(_image.Image, image, ignore_missing=ignore_missing)
def find_image(self, name_or_id, ignore_missing=False):
"""Find a single image
:param string name_or_id: The name or ID of a image.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: :class:`~ecl.compute.v2.image.Image` or None
"""
return self._find(_image.Image, name_or_id,
ignore_missing=ignore_missing)
def get_image(self, image):
"""Get a single image
:param image: The value can be the ID of an image or a
:class:`~ecl.compute.v2.image.Image` instance.
:returns: :class:`~ecl.compute.v2.image.Image`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_image.Image, image)
def images(self, details=True, **query):
"""Return a list of images
:param bool details: When ``True``, returns
:class:`~ecl.compute.v2.image.ImageDetail` objects,
otherwise :class:`~ecl.compute.v2.image.Image`.
:param kwargs \*\*query: Optional query parameters to be sent to limit
the resources being returned.
:returns: A list of :class:`~ecl.compute.v2.image.Image`
"""
img = _image.ImageDetail if details else _image.Image
return list(self._list(img, paginated=True, **query))
def _get_base_resource(self, res, base):
# Metadata calls for Image and Server can work for both those
# resources but also ImageDetail and ServerDetail. If we get
# either class, use it, otherwise create an instance of the base.
if isinstance(res, base):
return res
else:
return base(id=res)
def get_image_metadata(self, image):
"""Return a dictionary of metadata for an image
:param image: Either the ID of an image or a
:class:`~ecl.compute.v2.image.Image` or
:class:`~ecl.compute.v2.image.ImageDetail`
instance.
:returns: A :class:`~ecl.compute.v2.image.Image` with only the
image's metadata. All keys and values are Unicode text.
:rtype: :class:`~ecl.compute.v2.image.Image`
"""
res = self._get_base_resource(image, _image.Image)
metadata = res.get_metadata(self.session)
result = _image.Image.existing(id=res.id, metadata=metadata)
return result
def set_image_metadata(self, image, **metadata):
"""Update metadata for an image
:param image: Either the ID of an image or a
:class:`~ecl.compute.v2.image.Image` or
:class:`~ecl.compute.v2.image.ImageDetail`
instance.
:param kwargs metadata: Key/value pairs to be updated in the image's
metadata. No other metadata is modified
by this call. All keys and values are stored
as Unicode.
:returns: A :class:`~ecl.compute.v2.image.Image` with only the
image's metadata. All keys and values are Unicode text.
"""
res = self._get_base_resource(image, _image.Image)
metadata = res.set_metadata(self.session, **metadata)
result = _image.Image.existing(id=res.id, metadata=metadata)
return result
def delete_image_metadata(self, image, keys):
"""Delete metadata for an image
:param image: Either the ID of an image or a
:class:`~ecl.compute.v2.image.Image` or
:class:`~ecl.compute.v2.image.ImageDetail`
instance.
:param array keys: The keys to delete.
:rtype: ``None``
"""
res = self._get_base_resource(image, _image.Image)
return res.delete_metadata(self.session, keys)
def create_keypair(self, name=None, public_key=None):
"""Create a new keypair from attributes
:param string name: The name to associate with the keypair.
:param string public_key: The public ssh key to import.
If not provided, a key is generated.
:returns: :class:`~ecl.compute.v2.keypair.Keypair`
"""
body = {}
if name is not None:
body.update({"name": name})
if public_key is not None:
body.update({"public_key": public_key})
return self._create(_keypair.Keypair, **body)
def delete_keypair(self, keypair, ignore_missing=False):
"""Delete a keypair
:param keypair: The value can be either the ID of a keypair or a
:class:`~ecl.compute.v2.keypair.Keypair`
instance.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the keypair does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent keypair.
:returns: ``None``
"""
self._delete(_keypair.Keypair, keypair, ignore_missing=ignore_missing)
def get_keypair(self, keypair):
"""Get a single keypair
:param keypair: The value can be the ID of a keypair or a
:class:`~ecl.compute.v2.keypair.Keypair`
instance.
:returns: :class:`~ecl.compute.v2.keypair.Keypair`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_keypair.Keypair, keypair)
def find_keypair(self, name_or_id, ignore_missing=False):
"""Find a single keypair
:param string name_or_id: The name or ID of a keypair.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: :class:`~ecl.compute.v2.keypair.Keypair` or None
"""
return self._find(_keypair.Keypair, name_or_id,
ignore_missing=ignore_missing)
def keypairs(self):
"""Return a list of keypairs
:returns: A list of keypair objects
:rtype: :class:`~ecl.compute.v2.keypair.Keypair`
"""
return list(self._list(_keypair.Keypair, paginated=False))
def get_limits(self):
"""Retrieve limits that are applied to the project's account
:returns: A Limits object, including both
:class:`~ecl.compute.v2.limits.AbsoluteLimits` and
:class:`~ecl.compute.v2.limits.RateLimits`
:rtype: :class:`~ecl.compute.v2.limits.Limits`
"""
return self._get(limits.Limits)
def availability_zones(self, details=False):
"""Return a list of availability zones
:param bool details: Return extra details about the availability
zones. This defaults to `False` as it generally
requires extra permission.
:returns: A list of :class:`~ecl.compute.v2.availability_zone.AvailabilityZone`
"""
if details:
az = _availability_zone.AvailabilityZoneDetail
else:
az = _availability_zone.AvailabilityZone
return list(self._list(az, paginated=False))
def find_availability_zone(self, name_or_id, ignore_missing=False):
"""Find a single availability_zone
:param string name_or_id: The name or ID of a availability_zone.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: :class:`~ecl.compute.v2.availability_zone.AvailabilityZone` or None
"""
return self._find(_availability_zone.AvailabilityZone, name_or_id,
ignore_missing=ignore_missing)
def get_quota(self, tenant_id):
"""Get quota info of a tenant
:param tenant_id: The ID for the tenant for which you want to show
quotas. This ID is different from the tenant ID of authentication.
That ID is for the admin tenant.
:returns: :class:`~ecl.compute.v2.quota.Quota`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_quota.Quota, tenant_id)
def get_default_quota(self, tenant_id):
"""Get default quota info of a tenant
:param string tenant_id: The ID for the tenant for which you want to show
quotas. This ID is different from the tenant ID of authentication.
That ID is for the admin tenant.
:returns: :class:`~ecl.compute.v2.quota.DefaultQuota`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_quota.DefaultQuota, tenant_id=tenant_id)
def get_tenant_usage(self, tenant_id):
"""Get tenant usage information of a tenant
:param string tenant_id: The ID for the tenant for which you want to show
usage information. This ID is different from the tenant ID of authentication.
That ID is for the admin tenant.
:returns: :class:`~ecl.compute.v2.quota.TenantUsage`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_quota.TenantUsage, tenant_id)
def volumes(self, details=True):
"""Return a list of volumes
:param bool details: Return extra details about the volumes
This defaults to `False` as it generally
requires extra permission.
:returns: A list of :class:`~ecl.compute.v2.volume.Volume`
"""
if details:
vol = _volume.Volume
else:
vol = _volume.VolumeDetail
return list(self._list(vol, paginated=False))
def get_volume(self, volume):
"""Get a single volume
:param volume: The value can be the ID of a volume or a
:class:`~ecl.compute.v2.volume.Volume` instance.
:returns: :class:`~ecl.compute.v2.volume.Volume`
:raises: :class:`~ecl.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_volume.Volume, volume)
def create_volume(self, size, name=None, description=None,
volume_type=None, metadata=None, availability_zone=None,
snapshot_id=None):
"""Create a single volume
:param size: size of volume to create.
:param name: display name of volume to create.
:param description: display description of volume to create.
:param volume_type: volume type of volume to create.
:param metadata: size of metadata to create.
:param availability_zone: availability zone of volume to create.
:param snapshot_id: ID of snapshot to create from.
:returns: :class:`~ecl.compute.v2.volume.Volume`
"""
body = {"size": size}
if name:
body.update({"name": name})
if description:
body.update({"description": description})
if volume_type:
body.update({"volume_type": volume_type})
if metadata:
body.update({"metadata": metadata})
if availability_zone:
body.update({"availability_zone": availability_zone})
if snapshot_id:
body.update({"snapshot_id": snapshot_id})
return self._create(_volume.Volume, **body)
def delete_volume(self, volume, ignore_missing=False):
"""Delete an volume
:param volume: The value can be either the ID of an volume or a
:class:`~ecl.compute.v2.volume.Volume` instance.
:param bool ignore_missing: When set to ``False``
:class:`~ecl.exceptions.ResourceNotFound` will be
raised when the volume does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent volume.
:returns: ``None``
"""
self._delete(_volume.Volume, volume, ignore_missing=ignore_missing)
|
<reponame>bsimons/django-fiber
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.template import Template, Context, TemplateSyntaxError
from django.test import TestCase, SimpleTestCase
from fiber.models import Page, ContentItem, PageContentItem
from ...test_util import RenderMixin
class TestShowPageContent(RenderMixin, TestCase):
def setUp(self):
self.home = Page.objects.create(title='Home')
self.home_content = home = ContentItem.objects.create(content_html='<p>homepage</p>')
self.home_page_content = PageContentItem.objects.create(content_item=home, page=self.home, block_name='main')
self.about = Page.objects.create(title='About')
self.about_content = about = ContentItem.objects.create(content_html='<p>about</p>')
self.about_page_content = PageContentItem.objects.create(content_item=about, page=self.about, block_name='main')
# Staff user
self.staff = User.objects.create_user('staff', '<EMAIL>', password='<PASSWORD>')
self.staff.is_staff = True
self.staff.save()
def test_show_page_content(self):
self.assertRendered(
'{% load fiber_tags %}{% show_page_content "main" %}',
'<div><div class="content"><p>homepage</p></div></div>',
{'fiber_page': self.home})
def test_show_page_content_for_staff(self):
self.assertRendered(
'{% load fiber_tags %}{% show_page_content "main" %}',
'''
<div data-fiber-data='{ "can_edit":true, "type": "content_item", "add_url": "%(add_url)s", "page_id": %(home_pk)s, "block_name": "main" }'>
<div data-fiber-data='{ "can_edit": true, "type": "content_item", "id": %(home_content_pk)s, "url": "%(edit_url_home_content)s", "add_url": "%(add_url)s", "page_id": %(home_pk)s, "block_name": "main", "page_content_item_id": %(home_page_content_pk)s, "used_on_pages": [{"title": "Home", "url": ""}] }' class="content">
<p>homepage</p>
</div>
</div>''' % {
'home_pk': self.home.pk,
'add_url': reverse('fiber_admin:fiber_contentitem_add'),
'home_page_content_pk': self.home_page_content.pk,
'home_content_pk': self.home_content.pk,
'edit_url_home_content': reverse('fiber_admin:fiber_contentitem_change', args=[self.home_content.pk])
}, {'fiber_page': self.home, 'user': self.staff})
def test_show_page_content_with_other(self):
"""The show_page_content templatetag should support rendering content from multiple pages in one view."""
self.assertRendered(
'{% load fiber_tags %}{% show_page_content about_page "main" %}{% show_page_content "main" %}',
'<div><div class="content"><p>about</p></div></div><div><div class="content"><p>homepage</p></div></div>',
{'fiber_page': self.home, 'about_page': self.about})
def test_show_page_content_with_other_for_staff(self):
self.assertRendered(
'{% load fiber_tags %}{% show_page_content about_page "main" %}{% show_page_content "main" %}',
'''
<div data-fiber-data='{ "can_edit":true, "type": "content_item", "add_url": "%(add_url)s", "page_id": %(about_pk)s, "block_name": "main" }'>
<div data-fiber-data='{ "can_edit": true, "type": "content_item", "id": %(about_content_pk)s, "url": "%(edit_url_about_content)s", "add_url": "%(add_url)s", "page_id": %(about_pk)s, "block_name": "main", "page_content_item_id": %(about_page_content_pk)s, "used_on_pages": [{"title": "About", "url": ""}] }' class="content">
<p>about</p>
</div>
</div>
<div data-fiber-data='{ "can_edit":true, "type": "content_item", "add_url": "%(add_url)s", "page_id": %(home_pk)s, "block_name": "main" }'>
<div data-fiber-data='{ "can_edit": true, "type": "content_item", "id": %(home_content_pk)s, "url": "%(edit_url_home_content)s", "add_url": "%(add_url)s", "page_id": %(home_pk)s, "block_name": "main", "page_content_item_id": %(home_page_content_pk)s, "used_on_pages": [{"title": "Home", "url": ""}] }' class="content">
<p>homepage</p>
</div>
</div>''' % {
'about_pk': self.about.pk,
'home_pk': self.home.pk,
'add_url': reverse('fiber_admin:fiber_contentitem_add'),
'about_page_content_pk': self.about_page_content.pk,
'home_page_content_pk': self.home_page_content.pk,
'about_content_pk': self.about_content.pk,
'home_content_pk': self.home_content.pk,
'edit_url_about_content': reverse('fiber_admin:fiber_contentitem_change', args=[self.about_content.pk]),
'edit_url_home_content': reverse('fiber_admin:fiber_contentitem_change', args=[self.home_content.pk])
}, {'fiber_page': self.home, 'about_page': self.about, 'user': self.staff})
def test_single_argument_lookup(self):
self.assertRendered(
'{% load fiber_tags %}{% show_page_content main %}',
'<div><div class="content"><p>homepage</p></div></div>',
{'fiber_page': self.home, 'main': 'main'})
def test_two_argument_lookup(self):
self.assertRendered(
'{% load fiber_tags %}{% show_page_content about_page main %}',
'<div><div class="content"><p>about</p></div></div>',
{'fiber_page': self.home, 'about_page': self.about, 'main': 'main'})
def test_on_non_fiber_page(self):
"""
show_page_content on a non fiber page
"""
self.assertRendered('{% load fiber_tags %}{% show_page_content "main" %}', '')
class TestSyntaxErrors(TestCase):
def test_with_fiber_page_but_no_block_name(self):
"""
show_page_content with only a given fiber page
"""
about = Page.objects.create(title='About')
with self.assertRaises(TemplateSyntaxError) as cm:
Template('{% load fiber_tags %}{% show_page_content about %}').render(Context({'about': about}))
self.assertEqual(str(cm.exception), "'show_page_content' received invalid arguments")
def test_wrong_two_arguments(self):
"""
show_page_content with two strings cannot work
"""
with self.assertRaises(TemplateSyntaxError) as cm:
Template('{% load fiber_tags %}{% show_page_content "page" "main" %}').render(Context({}))
self.assertEqual(str(cm.exception), "'show_page_content' received invalid arguments")
|
#!/usr/bin/python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Converts profile datasets to dictionary list for Autofill profiles.
Used for test autofill.AutofillTest.testMergeDuplicateProfilesInAutofill.
Can be used as a stand alone script with -h to print out help text by running:
python autofill_dataset_converter.py -h
"""
import codecs
import logging
import os
import re
import sys
class _NullHandler(logging.Handler):
"""Prevents warning when running in quiet mode."""
def emit(self, record):
pass
class DatasetConverter(object):
_fields = [
u'NAME_FIRST',
u'NAME_MIDDLE',
u'NAME_LAST',
u'EMAIL_ADDRESS',
u'COMPANY_NAME',
u'ADDRESS_HOME_LINE1',
u'ADDRESS_HOME_LINE2',
u'ADDRESS_HOME_CITY',
u'ADDRESS_HOME_STATE',
u'ADDRESS_HOME_ZIP',
u'ADDRESS_HOME_COUNTRY',
u'PHONE_HOME_WHOLE_NUMBER',
u'PHONE_FAX_WHOLE_NUMBER',
]
_record_length = len(_fields)
_output_pattern = u'{'
for key in _fields:
_output_pattern += u"u'%s': u'%%s', " % key
_output_pattern = _output_pattern[:-1] + '},'
_re_single_quote = re.compile("'", re.UNICODE)
_logger = logging.getLogger(__name__)
_logger.addHandler(_NullHandler())
_log_handlers = {'StreamHandler': None}
def __init__(self, input_filename, output_filename=None,
logging_level=None):
"""Constructs a dataset converter object.
Full input pattern:
'(?P<NAME_FIRST>.*?)\|(?P<MIDDLE_NAME>.*?)\|(?P<NAME_LAST>.*?)\|
(?P<EMAIL_ADDRESS>.*?)\|(?P<COMPANY_NAME>.*?)\|(?P<ADDRESS_HOME_LINE1>.*?)
\|(?P<ADDRESS_HOME_LINE2>.*?)\|(?P<ADDRESS_HOME_CITY>.*?)\|
(?P<ADDRESS_HOME_STATE>.*?)\|(?P<ADDRESS_HOME_ZIP>.*?)\|
(?P<ADDRESS_HOME_COUNTRY>.*?)\|
(?P<PHONE_HOME_WHOLE_NUMBER>.*?)\|(?P<PHONE_FAX_WHOLE_NUMBER>.*?)$'
Full ouput pattern:
"{u'NAME_FIRST': u'%s', u'NAME_MIDDLE': u'%s', u'NAME_LAST': u'%s',
u'EMAIL_ADDRESS': u'%s', u'COMPANY_NAME': u'%s', u'ADDRESS_HOME_LINE1':
u'%s', u'ADDRESS_HOME_LINE2': u'%s', u'ADDRESS_HOME_CITY': u'%s',
u'ADDRESS_HOME_STATE': u'%s', u'ADDRESS_HOME_ZIP': u'%s',
u'ADDRESS_HOME_COUNTRY': u'%s', u'PHONE_HOME_WHOLE_NUMBER': u'%s',
u'PHONE_FAX_WHOLE_NUMBER': u'%s',},"
Args:
input_filename: name and path of the input dataset.
output_filename: name and path of the converted file, default is none.
logging_level: set verbosity levels, default is ERROR.
Raises:
IOError: error if input file does not exist.
"""
if logging_level:
if not self._log_handlers['StreamHandler']:
console = logging.StreamHandler()
console.setLevel(logging_level)
self._log_handlers['StreamHandler'] = console
self._logger.addHandler(console)
self._logger.setLevel(logging_level)
else:
if self._log_handlers['StreamHandler']:
self._logger.removeHandler(self._log_handlers['StreamHandler'])
self._log_handler['StreamHandler'] = None
self._input_filename = os.path.join(os.path.dirname(sys.argv[0]),
input_filename)
if not os.path.isfile(self._input_filename):
msg = 'File "%s" does not exist' % self._input_filename
self._logger.error(msg)
raise IOError(msg)
self._output_filename = output_filename
def _CreateDictionaryFromRecord(self, record):
"""Constructs and returns a dictionary from a record in the dataset file.
Escapes single quotation first and uses split('|') to separate values.
The method assumes a valid record always contains at least one "|"
character.
Example:
Take an argument as a string u'John|Doe|Mountain View'
and returns a dictionary
{
u'NAME_FIRST': u'John',
u'NAME_LAST': u'Doe',
u'ADDRESS_HOME_CITY': u'Mountain View',
}
Args:
record: row of record from the dataset file.
Returns:
None if the current record line is invalid or a dictionary representing a
single record from the dataset file.
"""
# Ignore irrelevant record lines that do not contain '|'.
if not '|' in record:
return
# Escaping single quote: "'" -> "\'"
record = self._re_single_quote.sub(r"\'", record)
record_list = record.split('|')
if record_list:
# Check for case when a record may have more or less fields than expected.
if len(record_list) != self._record_length:
self._logger.warning(
'A "|" separated line has %d fields instead of %d: %s' % (
len(record_list), self._record_length, record))
return
out_record = {}
for i, key in enumerate(self._fields):
out_record[key] = record_list[i]
return out_record
def Convert(self):
"""Function to convert input data into the desired output format.
Returns:
List that holds all the dictionaries.
"""
input_file = open(self._input_filename)
if self._output_filename:
output_file = codecs.open(self._output_filename, mode='wb',
encoding='utf-8-sig')
else:
output_file = None
try:
list_of_dict = []
i = 0
if output_file:
output_file.write('[')
output_file.write(os.linesep)
for line in input_file.readlines():
line = line.strip()
if not line:
continue
line = unicode(line, 'UTF-8')
output_record = self._CreateDictionaryFromRecord(line)
if output_record:
i += 1
list_of_dict.append(output_record)
output_line = self._output_pattern % tuple(
[output_record[key] for key in self._fields])
if output_file:
output_file.write(output_line)
output_file.write(os.linesep)
self._logger.info('%d: %s' % (i, line.encode(sys.stdout.encoding,
'ignore')))
self._logger.info('\tconverted to: %s' %
output_line.encode(sys.stdout.encoding, 'ignore'))
if output_file:
output_file.write(']')
output_file.write(os.linesep)
self._logger.info('%d lines converted SUCCESSFULLY!' % i)
self._logger.info('--- FINISHED ---')
return list_of_dict
finally:
if output_file:
output_file.close()
def main():
# Command line options.
from optparse import OptionParser
input_filename = os.path.join('..', 'data', 'autofill', 'dataset.txt')
output_filename = os.path.join('..', 'data', 'autofill',
'dataset_duplicate-profiles.txt')
parser = OptionParser()
parser.add_option('-i', '--input', dest='input_filename',
default=input_filename,
help='convert FILE [defaults to "%s"]' % input_filename,
metavar='FILE')
parser.add_option('-o', '--output', dest='output_filename',
default=output_filename,
help='write output to FILE [defaults to "%s"]' %
output_filename, metavar='FILE')
parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
default=True, help='display all [default]')
parser.add_option('-q', '--quiet', action='store_false', dest='verbose',
help='display nothing')
parser.add_option('-l', '--log', dest='logging_level', default=None,
help='specify logging LEVEL: "info", "warning" or "error"',
metavar='LEVEL')
(options, args) = parser.parse_args()
if args:
parser.print_help()
sys.exit(1)
if not options.verbose:
options.logging_level = None
if options.verbose and not options.logging_level:
options.logging_level = 'info'
if options.logging_level:
if 'info' in options.logging_level.lower():
options.logging_level = logging.INFO
elif 'warn' in options.logging_level.lower():
options.logging_level = logging.WARNING
elif 'error' in options.logging_level.lower():
options.logging_level = logging.ERROR
c = DatasetConverter(options.input_filename, options.output_filename,
options.logging_level)
c.Convert()
if __name__ == '__main__':
main()
|
"""
Tests scripts in the DBM folder
"""
import os
import pylearn2.scripts.dbm.show_negative_chains as negative_chains
import pylearn2.scripts.dbm.show_reconstructions as show_reconstruct
import pylearn2.scripts.dbm.show_samples as show_samples
import pylearn2.scripts.dbm.top_filters as top_filters
from pylearn2.config import yaml_parse
from pylearn2.models.dbm.layer import BinaryVector, BinaryVectorMaxPool
from pylearn2.datasets.mnist import MNIST
from pylearn2.models.dbm.dbm import DBM
from nose.tools import with_setup
from pylearn2.datasets import control
from pylearn2.utils import serial
from theano import function
from theano.compat.six.moves import cPickle
def setup():
"""
Create pickle file with a simple model.
"""
# tearDown is guaranteed to run pop_load_data.
control.push_load_data(False)
with open('dbm.pkl', 'wb') as f:
dataset = MNIST(which_set='train', start=0, stop=100, binarize=True)
vis_layer = BinaryVector(nvis=784, bias_from_marginals=dataset)
hid_layer1 = BinaryVectorMaxPool(layer_name='h1', pool_size=1,
irange=.05, init_bias=-2.,
detector_layer_dim=50)
hid_layer2 = BinaryVectorMaxPool(layer_name='h2', pool_size=1,
irange=.05, init_bias=-2.,
detector_layer_dim=10)
model = DBM(batch_size=20, niter=2, visible_layer=vis_layer,
hidden_layers=[hid_layer1, hid_layer2])
model.dataset_yaml_src = """
!obj:pylearn2.datasets.binarizer.Binarizer {
raw: !obj:pylearn2.datasets.mnist.MNIST {
which_set: "train",
start: 0,
stop: 100
}
}
"""
model.layer_to_chains = model.make_layer_to_state(1)
cPickle.dump(model, f, protocol=cPickle.HIGHEST_PROTOCOL)
def teardown():
"""Delete the pickle file created for the tests"""
if os.path.isfile('dbm.pkl'):
os.remove('dbm.pkl')
control.pop_load_data()
@with_setup(setup, teardown)
def test_show_negative_chains():
"""Test the show_negative_chains script main function"""
negative_chains.show_negative_chains('dbm.pkl')
@with_setup(setup, teardown)
def test_show_reconstructions():
"""Test the reconstruction update_viewer function"""
rows = 5
cols = 10
m = rows * cols
model = show_reconstruct.load_model('dbm.pkl', m)
dataset = show_reconstruct.load_dataset(model.dataset_yaml_src,
use_test_set='n')
batch = model.visible_layer.space.make_theano_batch()
reconstruction = model.reconstruct(batch)
recons_func = function([batch], reconstruction)
vis_batch = dataset.get_batch_topo(m)
patch_viewer = show_reconstruct.init_viewer(dataset, rows, cols, vis_batch)
show_reconstruct.update_viewer(dataset, batch, rows, cols, patch_viewer,
recons_func, vis_batch)
@with_setup(setup, teardown)
def test_show_samples():
"""Test the samples update_viewer function"""
rows = 10
cols = 10
m = rows * cols
model = show_samples.load_model('dbm.pkl', m)
dataset = yaml_parse.load(model.dataset_yaml_src)
samples_viewer = show_samples.init_viewer(dataset, rows, cols)
vis_batch = dataset.get_batch_topo(m)
show_samples.update_viewer(dataset, samples_viewer, vis_batch, rows, cols)
@with_setup(setup, teardown)
def test_top_filters():
"""Test the top_filters viewer functions"""
model = serial.load('dbm.pkl')
layer_1, layer_2 = model.hidden_layers[0:2]
W1 = layer_1.get_weights()
W2 = layer_2.get_weights()
top_filters.get_mat_product_viewer(W1, W2)
dataset_yaml_src = model.dataset_yaml_src
dataset = yaml_parse.load(dataset_yaml_src)
imgs = dataset.get_weights_view(W1.T)
top_filters.get_connections_viewer(imgs, W1, W2)
|
"""
Description: This script generates ASYMP for baselines
# NOTE: For this, we're not sharing the actual patient data, so comment out Strategy3
"""
from utils.networkx_operations import *
from utils.pandas_operations import *
from utils.time_operations import *
import pandas as pd
import numpy as np
import argparse
import pickle
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='d_steiner on month1')
parser.add_argument('-beta', '--beta', type=int, default=1,
help= 'beta in 1, 2, 4')
args = parser.parse_args()
beta = args.beta
x = 1
start_date = pd.Timestamp(2010, 1, 1)
end_date = pd.Timestamp(2010, 2, 1)
G = nx.read_graphml("data/G_synthetic_step2_beta{}_x{}_v3.graphml".format(beta, x))
G = relabel_nodes_str_to_tuple(G)
terminal_node_set = set([v for v in G.nodes() if G.nodes[v]["terminal"]])
print("terminal nodes: {}".format(len(terminal_node_set)))
##########################################################
# Strategy1: Frontier. Neighbors of terminal nodes. In time extended graph, src node for the edge into terminal_case (ASYMP, terminal_case)
ASYMP_frontier_list = []
for terminal_node in terminal_node_set:
neighbor_node_list = [u for u, v in G.in_edges(terminal_node)]
ASYMP_frontier_list.extend(neighbor_node_list)
ASYMP_frontier_set = set(ASYMP_frontier_list)
ASYMP_frontier_set = ASYMP_frontier_set - terminal_node_set
##########################################################
# Strategy2: Contact. Based on out degree 3% 5% 10%
n_nodes = len(G)
node_outdegree_pair_sorted = sorted(G.out_degree, key=lambda x: x[1], reverse=True)
node_outdegree_sorted = [node for node, degree in node_outdegree_pair_sorted]
ASYMP_contact_top3_set = set(node_outdegree_sorted[:int(n_nodes * 0.03)])
ASYMP_contact_top5_set = set(node_outdegree_sorted[:int(n_nodes * 0.05)])
ASYMP_contact_top10_set = set(node_outdegree_sorted[:int(n_nodes * 0.10)])
ASYMP_contact_top3_set = ASYMP_contact_top3_set - terminal_node_set
ASYMP_contact_top5_set = ASYMP_contact_top5_set - terminal_node_set
ASYMP_contact_top10_set = ASYMP_contact_top10_set - terminal_node_set
##########################################################
# NOTE: For this, we're not sharing the actual patient data, so comment out Strategy3
# Strategy3: LOS. Based on LOS. Based on 3% 5% 10%
df_CDI_cum = pd.read_csv("../prepare_input_for_PCST/data/CDI_EMR_cum.csv", parse_dates=["date"])
df_CDIx_cum = pd.read_csv("../prepare_input_for_PCST/data/CDIx_EMR_cum.csv", parse_dates=["date"])
df_CDI_cum = filter_records(df_CDI_cum, start_date, end_date)
df_CDIx_cum = filter_records(df_CDIx_cum, start_date, end_date)
df_dataset = pd.concat([
df_CDI_cum[["vid", "date", "los"]],
df_CDIx_cum[["vid", "date", "los"]]
], axis=0)
df_dataset = df_dataset.sort_values(by="los", ascending=False)
day_array = (df_dataset.date - start_date).dt.days.values
df_dataset.insert(loc=1, column="day", value=day_array)
node_array = df_dataset[["vid", "day"]].apply(tuple, axis=1).values
df_dataset.insert(loc=0, column="node", value=node_array)
node_LOS_sorted = df_dataset.node.values
ASYMP_LOS_top3_set = set(node_LOS_sorted[:int(n_nodes * 0.03)])
ASYMP_LOS_top5_set = set(node_LOS_sorted[:int(n_nodes * 0.05)])
ASYMP_LOS_top10_set = set(node_LOS_sorted[:int(n_nodes * 0.10)])
ASYMP_LOS_top3_set = ASYMP_LOS_top3_set - terminal_node_set
ASYMP_LOS_top5_set = ASYMP_LOS_top5_set - terminal_node_set
ASYMP_LOS_top10_set = ASYMP_LOS_top10_set - terminal_node_set
##########################################################
# Save asymptomatics
ASYMP_dict = dict()
ASYMP_dict["frontier"] = ASYMP_frontier_set
ASYMP_dict["contact_top3"] = ASYMP_contact_top3_set
ASYMP_dict["contact_top5"] = ASYMP_contact_top5_set
ASYMP_dict["contact_top10"] = ASYMP_contact_top10_set
ASYMP_dict["LOS_top3"] = ASYMP_LOS_top3_set
ASYMP_dict["LOS_top5"] = ASYMP_LOS_top5_set
ASYMP_dict["LOS_top10"] = ASYMP_LOS_top10_set
pickle.dump(ASYMP_dict, open("data/EXP1_ASYMP_dict_beta{}.pkl".format(beta), "wb"))
print("number of frontiers: {}".format(len(ASYMP_dict["frontier"])))
|
<filename>util.py<gh_stars>1-10
#!/usr/bin/python
import numpy as np
import mido
import itertools
import math
import sys
#np.set_printoptions(formatter={'float': lambda x: str(x)+ '\t'})
NUM_FEATURES = 12
NUM_NOTES = 128
segmentedBeatsMidiFileCache = {}
# IMPORTANT: we assume the midi file has only one track!
# (ie, it is in format 0)
# This must hold for us to be able to analyze the entire group of instruments
# at once. Things get a little more complicated if it has more than one track.
def getNGramBarList(midiFileName, n=4): # n = 4 for four lists
if midiFileName in segmentedBeatsMidiFileCache:
midi = segmentedBeatsMidiFileCache[midiFileName]
else:
segmentedBeatsMidiFileCache[midiFileName] = SegmentedBeatsMidiFile(midiFileName)
midi = segmentedBeatsMidiFileCache[midiFileName]
assert(midi.getNumTracks() == 1)
return [midi.segmentIntoBars(barWidth=n, start=i) for i in range(n)]
# We assume that the midi file only sets its tempo once at the start of the file
# (which I assume is the case >95% of the time).
# We also assume (IMPORTANT) that the number of tracks, including the header
# track, is 1. This means that all the instruments are in the same track.
#
# ie, the midi file should be in format 0.
# If your midi file is in format 1 or 2, you can try to find a converter online.
class SegmentedBeatsMidiFile(mido.MidiFile):
def __init__(self, fileName):
mido.MidiFile.__init__(self, fileName)
assert(self.getNumTracks() == 1)
self.initDefaults()
self.loadMessages()
self.initHeaderInfo()
self.segmentIntoBeats()
def initDefaults(self):
self.tempo = 500000
# Doesn't load control_change or other messages yet.
# Only works with note_on messages, which is all we really need it to work for.
def loadMessages(self):
self.headerMessages = [message for track in self.tracks for message in track \
if isinstance(message, mido.MetaMessage)]
self.mainMessages = [message for track in self.tracks for message in track\
if message.type == 'note_on' and \
not isinstance(message, mido.MetaMessage)]
# Right now this only sets tempo because I think it's the only property
# that matters.
def initHeaderInfo(self):
for message in self.headerMessages:
if message.type == 'set_tempo':
self.tempo = message.tempo # microseconds per beat
self.beatsPerSecond = 1000000. / self.tempo
def segmentIntoBeats(self):
self.beats = []
messages = self.mainMessages
on = {} # A dict mapping from note : state.
# A state is a tuple (isOn, length) that
# tells whether note is currently on, and
# for how long it was turned on in the
# current beat, in ticks. isOn is a boolean.
index = 0
tickLimit = 0 # Represents how many ticks you have left.
# Each message m "consumes" m.time ticks.
result = []
# for each beat, do:
for i in xrange(self.getTotalBeats()):
# advance to next beat
tickLimit += self.ticks_per_beat
# iterate through all messages that can fit into these ticks
while index < len(self.mainMessages) and \
tickLimit - self.mainMessages[index].time >= 0:
message = self.mainMessages[index]
# add to total time being "on"
for note in on:
if(on[note][0]):
on[note] = (True, on[note][1] + min(self.ticks_per_beat, message.time))
if message.velocity == 0: # turn the note off
if message.note in on:
on[message.note] = (False, on[message.note][1])
else: # turn the note on
if message.note in on:
on[message.note] = (True, on[message.note][1])
else:
on[message.note] = (True, 0)
# consume this many ticks
tickLimit -= message.time
index += 1
# add to total time "on" for the rest of the beat
for note in on:
if(on[note][0]):
on[note] = (True, on[note][1] + tickLimit)
# Make a deep copy of on, doing some postprocessing:
# - Remove notes that are played for 0 ticks
# - Remove the (useless) first value of the tuple
# - Take the fraction of the length over the ticks per beat
result.append([(note, length / float(self.ticks_per_beat)) \
for note, (isOn, length) in on.items() if length > 0])
# Take out everything in on that's False
# and reset everything that's True to 0
toRemove = []
for note in on:
if(on[note][0]):
on[note] = (True, 0)
else:
toRemove.append(note)
for note in toRemove:
del on[note]
self.beats = result
def getTotalBeats(self):
if not hasattr(self, 'numBeats'):
self.numBeats = int(math.floor(self.beatsPerSecond * self.length + 1e-5))
return self.numBeats
def getTotalTicks(self):
return self.ticks_per_beat * self.getTotalBeats()
def getNumTracks(self):
return len(self.tracks)
# Assumes self.beats has already been calculated by
# self.segmentIntoBeats(). Joins those beats
# starting at the given index, with the given bar width.
def segmentIntoBars(self, barWidth=4, start=0):
assert(start < barWidth)
beats = ([None] * start) + self.beats
numBars = (len(beats) + barWidth - 1) // barWidth
bars = [0] * numBars
for i in xrange(numBars):
arr = []
for j in range(barWidth):
index = i * barWidth + j
if index < len(beats) and beats[index] is not None:
arr.append(beats[index])
bars[i] = Bar(list(arr), barWidth=barWidth)
return bars
# A Bar -- a list of beats
class Bar:
def __init__(self, beats, barWidth=4):
self.beats = beats
for i, beat in enumerate(self.beats):
for j, (note, length) in enumerate(beat):
self.beats[i][j] = (note, min(length, 1))
def __str__(self):
return str(self.beats)
def __repr__(self):
return str(self.beats)
def getKMeansFeatures(self):
v = [0] * NUM_FEATURES
for beat in self.beats:
for note, length in beat:
v[note % NUM_FEATURES] += length
return np.array(v)
# Doesn't work yet because velocity information is lost.
# Need to modify the "on" dict in segmentIntoBeats().
# Will do this later.
# Just pick a random one out of the four lists for now.
def getBarConfidenceFeatures(self):
if len(self.beats) == self.barWidth and self.beats[0]:
return 0 # sum(x for x in self.beats[0])
return 0
|
from game import Game
import random
import sys
import time
class RandomPlayer:
def __init__(self):
data = sys.stdin.readline().strip().split() # Initialize Environment
self.player = int(data[0]) - 1 # player can have values 0 and 1
self.n = int(data[1]) # n can have values 5, 6, or 7
self.time_left = int(data[2])
self.game = Game(self.n)
self.RingPos = {}
self.play()
# def placeRing(self):
# movetype = 'P'
# hexagon = random.randint(0,self.n)
# position = random.randint(0,max(0,6*hexagon-1))
# if hexagon==self.n and position%self.n==0:
# position+=1
# return '{type} {hex} {pos}'.format(type=movetype, hex=hexagon, pos=position), len(self.RingPos), hexagon, position
# def selectRing(self):
# movetype = 'S'
# ring_num = random.randint(0,self.n-1)
# while ring_num not in self.RingPos:
# ring_num = random.randint(0,self.n-1)
# ring = self.RingPos[ring_num]
# return '{type} {hex} {pos}'.format(type=movetype, hex=ring[0], pos=ring[1]), ring_num
# def moveRing(self):
# movetype = 'M'
# hexagon = random.randint(0,self.n)
# position = random.randint(0,max(0,6*hexagon-1))
# if hexagon==self.n and position%self.n==0:
# position+=1
# return '{type} {hex} {pos}'.format(type=movetype, hex=hexagon, pos=position), hexagon, position
# def removeRowStart(self):
# movetype = 'RS'
# hexagon = random.randint(0,self.n)
# position = random.randint(0,max(0,6*hexagon-1))
# if hexagon==self.n and position%self.n==0:
# position+=1
# return '{type} {hex} {pos}'.format(type=movetype, hex=hexagon, pos=position)
# def removeRowEnd(self):
# movetype = 'RE'
# hexagon = random.randint(0,self.n)
# position = random.randint(0,max(0,6*hexagon-1))
# if hexagon==self.n and position%self.n==0:
# position+=1
# return '{type} {hex} {pos}'.format(type=movetype, hex=hexagon, pos=position)
# def removeRing(self):
# movetype = 'X'
# ring_num = random.randint(0,self.n-1)
# while ring_num not in self.RingPos:
# ring_num = random.randint(0,self.n-1)
# ring = self.RingPos[ring_num]
# return '{type} {hex} {pos}'.format(type=movetype, hex=ring[0], pos=ring[1]), ring_num
# def play_move_seq(self, move_seq):
# // moves = ' '.join(move_seq) + '\n'
# sys.stdout.write(moves)
# sys.stdout.flush()
def play(self):
file = open("game.log", "r")
lines = file.readlines()
if self.player == 1:
move = sys.stdin.readline().strip()
count = self.player
sys.stderr.write("move_start " + str(count) + '\n')
while True: # Keep playing moves till game is over
move = lines[count].split("\"")[-2]
sys.stderr.write(move+"\n")
count+=2
sys.stdout.write(move+"\n")
sys.stdout.flush()
## Execute Other Player Move Sequence
move = sys.stdin.readline().strip()
# self.game.execute_move(move)
random_player = RandomPlayer()
|
<gh_stars>0
import psycopg2
from datetime import datetime
class Funcionario:
def __init__(self,nome,email,senha,login):
self._nome = nome
self._email = email
self._login = login
self._senha = senha
def _get_nome(self):
return self._nome
def _get_email(self):
return self._email
def _get_id(self):
return self._id
def _get_departamento(self):
return self._departamento
def _get_login(self):
return self._login
def _get_senha(self):
return self._senha
def _get_admin(self):
return self._admin
def _set_nome(self, nome):
self._nome = nome
def _set_email(self, email):
self._email = email
def _set_id(self, id):
self._id = id
def _set_departamento(self, departamento):
self._departamento = departamento
def _set_login(self,login):
self._login = login
def _set_senha(self,senha):
self._senha = senha
def _set_admin(self,admin):
self._admin = admin
nome = property(_get_nome,_set_nome)
email = property(_get_email,_set_email)
id = property(_get_id,_set_id)
departamento = property(_get_departamento,_set_departamento)
login = property(_get_login,_set_login)
senha = property(_get_senha,_set_senha)
admin = property(_get_admin,_set_admin)
class funcionarioDao:
def __init__(self):
self._conexao = "dbname=funcionario user=postgres password=postgres host=localhost port=5432"
def listar(self):
con = psycopg2.connect(self._conexao)
v=[]
with con as c:
cursor = c.cursor()
cursor.execute('select * from funcionario')
for l in cursor.fetchall():
f = Funcionario(l[1],l[2],l[4],l[6])
f.admin=l[5]
f.departamento=int(l[3])
f.id=l[0]
v.append(f)
cursor.close()
return v
def salvar(self, f):
verifica=hasattr(f, 'id')
if (verifica):
con = psycopg2.connect(self._conexao)
cursor = con.cursor()
cursor.execute('UPDATE Funcionario SET nome = %s, email = %s, idDepartamento = %s, login = %s, senha=%, admin=FALSE WHERE idFuncionario = %s',(f.nome,f.email,f.departamento,f.login,f.senha,int(f.id)))
con.commit()
cursor.close()
else:
con = psycopg2.connect(self._conexao)
cursor = con.cursor()
cursor.execute('insert into Funcionario (nome,email,idDepartamento,login,senha,admin) values (%s,%s,%s,%s,%s,FALSE) RETURNING idFuncionario', (f.nome,f.email,f.departamento,f.login,f.senha))
cod = (cursor.fetchone())[0]
con.commit()
f.id = int(cod)
cursor.close()
def buscar(self,cod):
con = psycopg2.connect(self._conexao)
cursor = con.cursor()
cursor.execute('SELECT * FROM Funcionario WHERE idFuncionario = %s',[cod])
l = cursor.fetchone()
f = Funcionario(l[1],l[2],l[4],l[6])
f.admin=l[5]
f.departamento=int(l[3])
f.id = int(l[0])
cursor.close()
return f
def excluir(self,id):
con = psycopg2.connect(self._conexao)
cursor = con.cursor()
cursor.execute('DELETE FROM Funcionario WHERE idFuncionario = %s',[id])
con.commit()
cursor.close()
def login(self,login,senha):
try:
con = psycopg2.connect(self._conexao)
cursor = con.cursor()
cursor.execute('SELECT * FROM Funcionario WHERE login = %s and senha= %s ',(login,senha))
l = cursor.fetchone()
#nome,email,idDepartamento,senha,admin,login
f = Funcionario(l[1],l[2],l[4],l[6])
f.admin=l[5]
f.departamento=int(l[3])
cursor.close()
return f
except TypeError:
return "O login e senha não correspondem às informações em nossos registros. Tente Novamente"
#f.departamento=d
#d.funcionario=f
#print(fdao.listar())
#print(f.departamento.id)
f1 = funcionarioDao()
f=Funcionario("nome","email","senha","login")
#f = f1.login("adm","adm")
#print(f)
#f = f1.buscar(1)
#print(f.nome)
#print(f.email)
#print(f.departamento)
#depto nao precisa de gerente
|
# Copyright (C) 2016 maxn <EMAIL>
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = '''
author: Unknown (!UNKNOWN)
name: jabber
type: notification
short_description: post task events to a jabber server
description:
- The chatty part of ChatOps with a Hipchat server as a target
- This callback plugin sends status updates to a HipChat channel during playbook execution.
requirements:
- xmpp (python lib https://github.com/ArchipelProject/xmpppy)
options:
server:
description: connection info to jabber server
required: True
env:
- name: JABBER_SERV
user:
description: Jabber user to authenticate as
required: True
env:
- name: JABBER_USER
password:
description: Password for the user to the jabber server
required: True
env:
- name: JABBER_PASS
to:
description: chat identifier that will receive the message
required: True
env:
- name: JABBER_TO
'''
import os
HAS_XMPP = True
try:
import xmpp
except ImportError:
HAS_XMPP = False
from ansible.plugins.callback import CallbackBase
class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_NAME = 'community.general.jabber'
CALLBACK_NEEDS_WHITELIST = True
def __init__(self, display=None):
super(CallbackModule, self).__init__(display=display)
if not HAS_XMPP:
self._display.warning("The required python xmpp library (xmpppy) is not installed. "
"pip install git+https://github.com/ArchipelProject/xmpppy")
self.disabled = True
self.serv = os.getenv('JABBER_SERV')
self.j_user = os.getenv('JABBER_USER')
self.j_pass = os.getenv('<PASSWORD>')
self.j_to = os.getenv('JABBER_TO')
if (self.j_user or self.j_pass or self.serv or self.j_to) is None:
self.disabled = True
self._display.warning('Jabber CallBack wants the JABBER_SERV, JABBER_USER, JABBER_PASS and JABBER_TO environment variables')
def send_msg(self, msg):
"""Send message"""
jid = xmpp.JID(self.j_user)
client = xmpp.Client(self.serv, debug=[])
client.connect(server=(self.serv, 5222))
client.auth(jid.getNode(), self.j_pass, resource=jid.getResource())
message = xmpp.Message(self.j_to, msg)
message.setAttr('type', 'chat')
client.send(message)
client.disconnect()
def v2_runner_on_ok(self, result):
self._clean_results(result._result, result._task.action)
self.debug = self._dump_results(result._result)
def v2_playbook_on_task_start(self, task, is_conditional):
self.task = task
def v2_playbook_on_play_start(self, play):
"""Display Playbook and play start messages"""
self.play = play
name = play.name
self.send_msg("Ansible starting play: %s" % (name))
def playbook_on_stats(self, stats):
name = self.play
hosts = sorted(stats.processed.keys())
failures = False
unreachable = False
for h in hosts:
s = stats.summarize(h)
if s['failures'] > 0:
failures = True
if s['unreachable'] > 0:
unreachable = True
if failures or unreachable:
out = self.debug
self.send_msg("%s: Failures detected \n%s \nHost: %s\n Failed at:\n%s" % (name, self.task, h, out))
else:
out = self.debug
self.send_msg("Great! \n Playbook %s completed:\n%s \n Last task debug:\n %s" % (name, s, out))
|
# uncompyle6 version 3.7.4
# Python bytecode 3.7 (3394)
# Decompiled from: Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]
# Embedded file name: T:\InGame\Gameplay\Scripts\Server\socials\jigs\jig_utils.py
# Compiled at: 2019-01-17 04:01:59
# Size of source mod 2**32: 13821 bytes
import collections
from sims.sim_info_types import Species, Age, SpeciesExtended
import enum, placement, routing, sims4.log
logger = sims4.log.Logger('Jig Utils')
with sims4.reload.protected(globals()):
on_jig_changed = sims4.callback_utils.CallableList()
class JigPositioning(enum.Int):
RelativeToSimB = 0
RelativeToSimA = 1
SIMS_3_DISTANCE_MATRIX = {Species.HUMAN: {Species.HUMAN: 0.7,
(
Species.HUMAN, Age.CHILD): 0.7,
Species.DOG: 1,
(
Species.DOG, Age.CHILD): 0.7,
Species.CAT: 1,
(
Species.CAT, Age.CHILD): 0.7},
(
Species.HUMAN, Age.CHILD): {Species.HUMAN: 0.7,
(
Species.HUMAN, Age.CHILD): 0.7,
Species.DOG: 1,
(
Species.DOG, Age.CHILD): 0.6,
Species.CAT: 0.7,
(
Species.CAT, Age.CHILD): 0.6},
Species.DOG: {Species.HUMAN: 1,
(
Species.HUMAN, Age.CHILD): 1,
Species.DOG: 1,
(
Species.DOG, Age.CHILD): 0.9,
Species.CAT: 1,
(
Species.CAT, Age.CHILD): 0.9},
(
Species.DOG, Age.CHILD): {Species.HUMAN: 0.7,
(
Species.HUMAN, Age.CHILD): 0.7,
Species.DOG: 1,
(
Species.DOG, Age.CHILD): 0.7,
Species.CAT: 1,
(
Species.CAT, Age.CHILD): 0.7},
Species.CAT: {Species.HUMAN: 1,
(
Species.HUMAN, Age.CHILD): 0.7,
Species.DOG: 1,
(
Species.DOG, Age.CHILD): 0.5,
Species.CAT: 0.6,
(
Species.CAT, Age.CHILD): 0.5},
(
Species.CAT, Age.CHILD): {Species.HUMAN: 0.7,
(
Species.HUMAN, Age.CHILD): 0.6,
Species.DOG: 0.9,
(
Species.DOG, Age.CHILD): 0.3,
Species.CAT: 0.5,
(
Species.CAT, Age.CHILD): 0.3}}
def get_sims3_social_distance(sim_a_species, sim_a_age, sim_b_species, sim_b_age):
sim_a_key = (
sim_a_species, sim_a_age)
sim_b_key = (sim_b_species, sim_b_age)
if sim_a_key not in SIMS_3_DISTANCE_MATRIX:
sim_a_key = sim_a_species
if sim_b_key not in SIMS_3_DISTANCE_MATRIX:
sim_b_key = sim_b_species
return SIMS_3_DISTANCE_MATRIX[sim_a_key][sim_b_key]
ReserveSpace = collections.namedtuple('_ReserveSpace', ('front', 'back', 'left', 'right'))
DEFAULT_RESERVE_SPACE = {Species.HUMAN: ReserveSpace(0.5, 0.5, 0.5, 0.5),
(
Species.HUMAN, Age.CHILD): ReserveSpace(0.5, 0.5, 0.5, 0.5),
Species.DOG: ReserveSpace(0.75, 1.0, 0.3, 0.3),
(
Species.DOG, Age.CHILD): ReserveSpace(0.4, 0.5, 0.3, 0.3),
Species.CAT: ReserveSpace(0.4, 0.5, 0.3, 0.3),
(
Species.CAT, Age.CHILD): ReserveSpace(0.2, 0.3, 0.2, 0.2),
SpeciesExtended.SMALLDOG: ReserveSpace(0.4, 0.5, 0.3, 0.3),
(
SpeciesExtended.SMALLDOG, Age.CHILD): ReserveSpace(0.4, 0.5, 0.3, 0.3)}
def get_default_reserve_space(species, age):
key = (
species, age)
if key not in DEFAULT_RESERVE_SPACE:
key = species
return DEFAULT_RESERVE_SPACE[key]
def _generate_poly_points(sim_a_translation, sim_a_fwd, sim_b_translation, sim_b_fwd, a_left, a_right, a_front, a_back, b_left, b_right, b_front, b_back):
all_points = []
sim_a_cross = sims4.math.vector_cross(sim_a_fwd, sims4.math.Vector3.Y_AXIS())
all_points.append(sim_a_translation + sim_a_fwd * a_front)
all_points.append(sim_a_translation + sim_a_cross * a_right)
all_points.append(sim_a_translation - sim_a_fwd * a_back)
all_points.append(sim_a_translation - sim_a_cross * a_left)
sim_b_cross = sims4.math.vector_cross(sim_b_fwd, sims4.math.Vector3.Y_AXIS())
all_points.append(sim_b_translation + sim_b_fwd * b_front)
all_points.append(sim_b_translation + sim_b_cross * b_right)
all_points.append(sim_b_translation - sim_b_fwd * b_back)
all_points.append(sim_b_translation - sim_b_cross * b_left)
polygon = sims4.geometry.Polygon(all_points)
return polygon.get_convex_hull()
def _generate_single_poly_rectangle_points(sim_a_translation, sim_z_vector, sim_x_vector, a_left, a_right, a_front, a_back):
all_points = [
sim_a_translation + (sim_x_vector * -a_left + sim_z_vector * a_back),
sim_a_translation + (sim_x_vector * a_right + sim_z_vector * a_back),
sim_a_translation + (sim_x_vector * -a_left + sim_z_vector * -a_front),
sim_a_translation + (sim_x_vector * a_right + sim_z_vector * -a_front)]
polygon = sims4.geometry.Polygon(all_points)
return polygon.get_convex_hull()
def generate_jig_polygon(loc_a, pos_a, rotation_a, loc_b, pos_b, rotation_b, a_left, a_right, a_front, a_back, b_left, b_right, b_front, b_back, positioning_type=JigPositioning.RelativeToSimB, fallback_routing_surface=None, reverse_nonreletive_sim_orientation=False, **fgl_kwargs):
if isinstance(pos_a, sims4.math.Vector2):
pos_a = sims4.math.Vector3(pos_a.x, 0, pos_a.y)
else:
if isinstance(pos_b, sims4.math.Vector2):
pos_b = sims4.math.Vector3(pos_b.x, 0, pos_b.y)
else:
sim_a_radians = rotation_a
sim_b_radians = rotation_b
def _generate_polygon_params(relative_loc, fwd_vec, relative_vec, rot_relative, rot_other):
polygon_fwd = relative_loc.transform.orientation.transform_vector(fwd_vec)
abs_vec_to_relative_sim = relative_loc.transform.orientation.transform_vector(relative_vec)
translation_relative = relative_loc.world_transform.translation
fwd_relative = sims4.math.vector3_rotate_axis_angle(polygon_fwd, rot_relative, sims4.math.Vector3.Y_AXIS())
translation_other = translation_relative - abs_vec_to_relative_sim
fwd_other = sims4.math.vector3_rotate_axis_angle(polygon_fwd, rot_other, sims4.math.Vector3.Y_AXIS())
routing_surface = relative_loc.routing_surface
if relative_loc.parent is not None:
routing_surface = relative_loc.parent.routing_surface
start_location = routing.Location(relative_loc.world_transform.translation, relative_loc.world_transform.orientation, routing_surface)
return (start_location, fwd_relative, translation_relative, fwd_other, translation_other, routing_surface)
if positioning_type == JigPositioning.RelativeToSimB:
vec_to_relative_sim = pos_b - pos_a
start_location, sim_b_fwd, sim_b_translation, sim_a_fwd, sim_a_translation, routing_surface = _generate_polygon_params(loc_b, -1 * sims4.math.Vector3.Z_AXIS(), vec_to_relative_sim, sim_b_radians, sim_a_radians)
else:
vec_to_relative_sim = pos_a - pos_b
start_location, sim_a_fwd, sim_a_translation, sim_b_fwd, sim_b_translation, routing_surface = _generate_polygon_params(loc_a, sims4.math.Vector3.Z_AXIS(), vec_to_relative_sim, sim_a_radians, sim_b_radians)
polygon = _generate_poly_points(sim_a_translation, sim_a_fwd, sim_b_translation, sim_b_fwd, a_left, a_right, a_front, a_back, b_left, b_right, b_front, b_back)
context = (placement.FindGoodLocationContext)(start_location, object_polygons=(polygon,), **fgl_kwargs)
new_translation, new_orientation = placement.find_good_location(context)
if new_translation is None:
if fallback_routing_surface is not None:
start_location.routing_surface = fallback_routing_surface
context = (placement.FindGoodLocationContext)(start_location, object_polygons=(polygon,), **fgl_kwargs)
new_translation, new_orientation = placement.find_good_location(context)
if new_translation is None:
return (None, None, None, None, None)
if positioning_type == JigPositioning.RelativeToSimB:
sim_b_translation = new_translation
sim_b_orientation = sims4.math.Quaternion.concatenate(new_orientation, sims4.math.angle_to_yaw_quaternion(sim_b_radians))
if reverse_nonreletive_sim_orientation:
sim_a_fwd = new_orientation.transform_vector(vec_to_relative_sim)
else:
sim_a_fwd = new_orientation.transform_vector(-1 * vec_to_relative_sim)
sim_a_translation = new_translation + new_orientation.transform_vector(-1 * vec_to_relative_sim)
sim_a_orientation = sims4.math.Quaternion.from_forward_vector(sims4.math.vector3_rotate_axis_angle(sim_a_fwd, sim_a_radians, sims4.math.Vector3.Y_AXIS()))
else:
sim_a_translation = new_translation
sim_a_orientation = sims4.math.Quaternion.concatenate(new_orientation, sims4.math.angle_to_yaw_quaternion(sim_a_radians))
if reverse_nonreletive_sim_orientation:
sim_b_fwd = new_orientation.transform_vector(vec_to_relative_sim)
else:
sim_b_fwd = new_orientation.transform_vector(-1 * vec_to_relative_sim)
sim_b_translation = new_translation + new_orientation.transform_vector(-1 * vec_to_relative_sim)
sim_b_orientation = sims4.math.Quaternion.concatenate(new_orientation, sims4.math.angle_to_yaw_quaternion(sim_b_radians))
return (sim_a_translation, sim_a_orientation, sim_b_translation, sim_b_orientation, routing_surface) |
<filename>saltred/saltarith.py
#! /usr/bin/env python
"""
saltarith is a copy of IRAF's imarith routine
but designed to deal with SALT's multi extension
data in a smart way.
Author Version Date
-----------------------------------------------
<NAME> (Madison) 1.0 16 July 2012
1.1 05 Aug 2012
<NAME> (SAAO) 1.2 13 Nov 2012
TODO
-----------------------------------------------
Updates
-----------------------------------------------
15 Aug 2012 Removed support for using the mean, as it can
only lead to Bad Things. Fits header is now
updated just like all other pysalt routines.
13 Nov 2012 -Added paremter file
-Added to PySALT package
"""
import time, numpy
from pyraf import iraf
import saltsafekey as saltkey
import saltsafeio as saltio
from saltsafelog import logging, history
from salterror import SaltError
debug=True
def saltarith(operand1, op, operand2, result, outpref, divzero=0, clobber=False, \
logfile='salt.log',verbose=True):
with logging(logfile,debug) as log:
# Check the input images
infiles = saltio.argunpack ('Input',operand1)
# create list of output files
outfiles=saltio.listparse('Outfile', result, outpref, infiles,'')
#verify that the input and output lists are the same length
saltio.comparelists(infiles,outfiles,'Input','output')
#let's keep track of whether operand2 is an image or not
is_image = False
#load in operand2, or, if it's not an image, assume it's a number
try: operand2struct = float(operand2)
except ValueError:
operand2struct = saltio.openfits(operand2)
is_image = True
#open the input image files
for infile, outfile in zip(infiles,outfiles):
struct = saltio.openfits(infile)
#do some math!
outstruct = arith(struct, op, operand2struct, is_image, divzero)
try:
pass
except Exception as e:
msg='Unable to do math %s because %s' % (infile, e)
raise SaltError(msg)
#update header stuff
fname, hist = history(level=1, wrap=False)
saltkey.housekeeping(struct[0],'SARITH', 'Some arithmatic was performed',hist)
#write it. close it.
saltio.writefits(outstruct,outfile,clobber=clobber)
saltio.closefits(struct)
#output the information
log.message('imarith: %s %s %s %s' % (infile, op, operand2, outfile), with_header=False, with_stdout=verbose)
#close the operand2 image
if is_image: saltio.closefits(operand2struct)
# -----------------------------------------------------------
# Actually do the math
def arith(struct, op, opstruct, is_image, divzero):
"""performs op on struct with opstruct as the argument
return struct
"""
# Determine the number of extensions
nextend=len(struct)
#do the math
for i in range(nextend):
if struct[i].name!='PRIMARY' or len(struct)==1:
#screw variance frames. Pay me more
#actually do the math
if is_image:
struct[i].data = eval('struct[i].data'+str(op)+'opstruct[i].data')
if op == '/':
#find where division by zero is going to happen
zidx = numpy.where(opstruct[i].data == 0)
struct[i].data[zidx] = divzero
else:
struct[i].data = eval('struct[i].data'+str(op)+'opstruct')
if op == '/' and opstruct == 0:
struct[i].data = numpy.ones(struct[i].data.shape)*divzero
return struct
# -----------------------------------------------------------
# main code
if not iraf.deftask('saltarith'):
parfile = iraf.osfn("saltred$saltarith.par")
t = iraf.IrafTaskFactory(taskname="saltarith",value=parfile,function=saltarith, pkgname='saltred')
|
import random
try:
import network
except ImportError:
from back import entity
try:
from ai import network
except ImportError:
from back.ai import network
VERBOSE = __name__ == '__main__'
class GenericAI:
def __init__(self, captors=4, neurones=4, choices=5, layer=2):
self.score = 0
self.year = 0
self.alive = True
self.name = random.choice([f"ent-{i}" for i in range(20)])
self.layer = layer
self.captors = captors
self.brain = network.Network(captors, neurones, choices, self.layer)
def __str__(self):
return f"{self.name}"
# -------------------------------------------------
def turn(self):
if not self.alive:
return
self.action()
self.year += 1
self.check_life()
def check_life(self):
# TODO check for out of bound
if self.year > 2 :
self.alive = False
# -------------------------------------------------
def action(self):
near_data = self.gather_data()
analysis = self.analyse(near_data)
thoughts = self.think(analysis)
choice = self.choose(thoughts)
return self.act(choice)
def gather_data(self):
collected_data = [random.random() for _ in range(self.captors)]
# predict best action ?
return collected_data
# -------------------------------------------------
def analyse(self, data):
return self.brain.analyse(data)
def think(self, thoughts):
'''
GenericAI's thoughts become its options, they then become potential choices
to eventually turn into actions.
'''
best, options = self.best_options(thoughts)
return self.filter(best, options)
def best_options(self, thoughts):
def rank(item):
return item[1]
# enumerate all options
options = dict(enumerate(thoughts))
# sort options by rank
ordered_options = dict(sorted(options.items(), key=rank, reverse=True))
best = next(iter(ordered_options.values()))
return best, ordered_options
def filter(self, best, options):
def get_best_choices(options, best):
return [choice for choice, opt in options.items() if opt == best]
return get_best_choices(options, best)
# -------------------------------------------------
def choose(self, choices):
# handle indecision
if len(choices) > 1:
verbose_print(f"\t{self.name} is facing a dilemma !")
return random.choice(choices)
return choices[0]
# -------------------------------------------------
def act(self, choice):
switch_case = {
0 : self.up,
1 : self.down,
2 : self.left,
3 : self.right,
4 : self.idle
}
switch_case.get(choice, self.idle)()
def up(self):
verbose_print("move up !")
def down(self):
verbose_print("move down !")
def left(self):
verbose_print("move left !")
def right(self):
verbose_print("move right !")
def idle(self):
verbose_print("stay idle !")
# -------------------------------------------------
def mutate(self, mutation_rate):
verbose_print(f"{self} mutate !")
self.brain.mutate(mutation_rate)
def crossover(self, parent):
ai = GenericAI(self.layer)
ai.brain = self.brain.crossover(parent.brain)
return ai
def clone(self):
ai = GenericAI(self.layer)
ai.brain = self.brain.clone()
return ai
# -------------------------------------------------
def calculate_fitness(self):
self.score += self.year*1
verbose_print(f"{self.name} : fitness = {round(self.score, 4)}")
# -------------------------------------------------
verbose_print = print if VERBOSE else lambda *a, **k: None
if __name__ == '__main__':
captors = 8
neurones = 10
choices = 5
layer = 2
ai = GenericAI(captors, neurones, choices, layer)
print(ai)
ai.action()
|
# -*- coding: utf-8 -*-
"""
Created on Wed May 1 17:41:15 2019
@author: Asus
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
dist_g_fn = lambda x,G_total: 1.0*(x.sum()+0.5) / G_total
dist_b_fn = lambda x,B_total: 1.0*(x.sum()+0.5) / B_total
n_fn = lambda x: x.sum()
def cal_iv_for_testset(df_test,iv_tab_train,y_colname,x_colname,p_good_ind):
#start
if p_good_ind == 0:
#convert Y
df_test = pd.concat([1- df_test[y_colname], df_test[x_colname]], axis=1, keys=['Y', 'X'])
else:
df_test = pd.concat([df_test[y_colname], df_test[x_colname]], axis=1, keys=['Y', 'X'])
df_test = df_test.loc[df_test['X'] != "."]
#copy the first 3 cols from the iv_tab_train
iv_tab_test = iv_tab_train[['RANGE','X_MIN','X_MAX']].copy()
Y = df_test['Y'].values.astype(np.float)
X = df_test['X'].values.astype(np.float)
N_list = []
Prec_N_list = []
G_list = []
B_list = []
woe_list = []
iv_list = []
N_total = len(X)
G_total = Y.sum()
B_total = N_total - G_total
for i in range(0,iv_tab_test.shape[0]):
#print(i)
row = iv_tab_test.iloc[i]
if i < iv_tab_test.shape[0] - 1:
#not last row
next_row = iv_tab_test.iloc[i+1]
else:
next_row = None
#print(X)
#print(row)
if i == 0:
#first row
N = len(X[X < next_row.X_MIN]) #N
G = (Y[X < next_row.X_MIN]).sum()
elif i == iv_tab_test.shape[0] - 1:
#last row
N = len(X[X >= row.X_MIN]) #N
G = (Y[X >= row.X_MIN]).sum()
else:
N = len(X[(X >= row.X_MIN) & (X < next_row.X_MAX)]) #N
G = (Y[(X >= row.X_MIN) & (X < next_row.X_MAX)]).sum()
perc_N = round(N/N_total,2) #N
B = N - G
dist_G = dist_g_fn(G,G_total)
dist_B = dist_b_fn(B,B_total)
woe = np.log(dist_G/dist_B)
iv = (1.0*(dist_G - dist_B)*np.log(dist_G/dist_B))
N_list.append(N)
Prec_N_list.append(perc_N)
G_list.append(G)
B_list.append(B)
woe_list.append(woe)
iv_list.append(iv)
iv_tab_test['N'] = N_list
iv_tab_test['%N'] = Prec_N_list
iv_tab_test['#GOOD'] = G_list
iv_tab_test['#BAD'] = B_list
iv_tab_test['WOE'] = woe_list
iv_tab_test['IV'] = iv_list
return iv_tab_test,iv_tab_test['IV'].sum()
def save_woe_test(sel_iv_tab,x_colname,p_cost_fn_name,folder_name='woe_pic'):
r = 'darkred'
g = 'darkgreen'
ax = sel_iv_tab.plot(kind='bar',x='RANGE',y='WOE',ylim = (-2.5,2.5), width=0.9
, color=sel_iv_tab["WOE"].apply(lambda x: g if x>0 else r))
ax.set_xlabel("Ranges")
ax.set_ylabel("WoE")
plt.tight_layout()
# #plt.savefig(x_colname+p_cost_fn_name+'.png', transparent=True)
plt.savefig('./{0}/'.format(folder_name)+x_colname+p_cost_fn_name+'.png')
plt.clf()
|
<filename>sktime/forecasting/base/tests/test_fh.py
# -*- coding: utf-8 -*-
# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)
"""Tests for ForecastingHorizon object."""
__author__ = ["mloning"]
import numpy as np
import pandas as pd
import pytest
from pytest import raises
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.base._fh import DELEGATED_METHODS
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.tests._config import (
INDEX_TYPE_LOOKUP,
TEST_FHS,
VALID_INDEX_FH_COMBINATIONS,
)
from sktime.utils._testing.forecasting import _make_fh, make_forecasting_problem
from sktime.utils._testing.series import _make_index
from sktime.utils.datetime import (
_coerce_duration_to_int,
_get_duration,
_get_freq,
_shift,
)
from sktime.utils.validation.series import VALID_INDEX_TYPES
def _assert_index_equal(a, b):
"""Compare forecasting horizons."""
assert isinstance(a, pd.Index)
assert isinstance(b, pd.Index)
assert a.equals(b)
@pytest.mark.parametrize(
"index_type, fh_type, is_relative", VALID_INDEX_FH_COMBINATIONS
)
@pytest.mark.parametrize("steps", TEST_FHS)
def test_fh(index_type, fh_type, is_relative, steps):
"""Testing ForecastingHorizon conversions."""
# generate data
y = make_forecasting_problem(index_type=index_type)
assert isinstance(y.index, INDEX_TYPE_LOOKUP.get(index_type))
# split data
y_train, y_test = temporal_train_test_split(y, test_size=10)
# choose cutoff point
cutoff = y_train.index[-1]
# generate fh
fh = _make_fh(cutoff, steps, fh_type, is_relative)
assert isinstance(fh.to_pandas(), INDEX_TYPE_LOOKUP.get(fh_type))
# get expected outputs
if isinstance(steps, int):
steps = np.array([steps])
fh_relative = pd.Int64Index(steps).sort_values()
fh_absolute = y.index[np.where(y.index == cutoff)[0] + steps].sort_values()
fh_indexer = fh_relative - 1
fh_oos = fh.to_pandas()[fh_relative > 0]
is_oos = len(fh_oos) == len(fh)
fh_ins = fh.to_pandas()[fh_relative <= 0]
is_ins = len(fh_ins) == len(fh)
# check outputs
# check relative representation
_assert_index_equal(fh_absolute, fh.to_absolute(cutoff).to_pandas())
assert not fh.to_absolute(cutoff).is_relative
# check relative representation
_assert_index_equal(fh_relative, fh.to_relative(cutoff).to_pandas())
assert fh.to_relative(cutoff).is_relative
# check index-like representation
_assert_index_equal(fh_indexer, fh.to_indexer(cutoff))
# check in-sample representation
# we only compare the numpy array here because the expected solution is
# formatted in a slightly different way than the generated solution
np.testing.assert_array_equal(
fh_ins.to_numpy(), fh.to_in_sample(cutoff).to_pandas()
)
assert fh.to_in_sample(cutoff).is_relative == is_relative
assert fh.is_all_in_sample(cutoff) == is_ins
# check out-of-sample representation
np.testing.assert_array_equal(
fh_oos.to_numpy(), fh.to_out_of_sample(cutoff).to_pandas()
)
assert fh.to_out_of_sample(cutoff).is_relative == is_relative
assert fh.is_all_out_of_sample(cutoff) == is_oos
def test_fh_method_delegation():
"""Test ForecastinHorizon delegated methods."""
fh = ForecastingHorizon(1)
for method in DELEGATED_METHODS:
assert hasattr(fh, method)
BAD_INPUT_ARGS = (
(1, 2), # tuple
"some_string", # string
0.1, # float
-0.1, # negative float
np.array([0.1, 2]), # float in array
None,
)
@pytest.mark.parametrize("arg", BAD_INPUT_ARGS)
def test_check_fh_values_bad_input_types(arg):
"""Negative test for bad ForecastingHorizon arguments."""
with raises(TypeError):
ForecastingHorizon(arg)
DUPLICATE_INPUT_ARGS = (
np.array([1, 2, 2]),
[3, 3, 1],
)
@pytest.mark.parametrize("arg", DUPLICATE_INPUT_ARGS)
def test_check_fh_values_duplicate_input_values(arg):
"""Negative test for ForecastingHorizon input arguments."""
with raises(ValueError):
ForecastingHorizon(arg)
GOOD_INPUT_ARGS = (
pd.Int64Index([1, 2, 3]),
pd.period_range("2000-01-01", periods=3, freq="D"),
pd.date_range("2000-01-01", periods=3, freq="M"),
np.array([1, 2, 3]),
[1, 2, 3],
1,
)
@pytest.mark.parametrize("arg", GOOD_INPUT_ARGS)
def test_check_fh_values_input_conversion_to_pandas_index(arg):
"""Test conversion to pandas index."""
output = ForecastingHorizon(arg, is_relative=False).to_pandas()
assert type(output) in VALID_INDEX_TYPES
TIMEPOINTS = [
pd.Period("2000", freq="M"),
pd.Timestamp("2000-01-01", freq="D"),
int(1),
3,
]
@pytest.mark.parametrize("timepoint", TIMEPOINTS)
@pytest.mark.parametrize("by", [-3, -1, 0, 1, 3])
def test_shift(timepoint, by):
"""Test shifting of ForecastingHorizon."""
ret = _shift(timepoint, by=by)
# check output type, pandas index types inherit from each other,
# hence check for type equality here rather than using isinstance
assert type(ret) is type(timepoint)
# check if for a zero shift, input and output are the same
if by == 0:
assert timepoint == ret
DURATIONS = [
pd.TimedeltaIndex(range(3), unit="D", freq="D"),
pd.TimedeltaIndex(range(0, 9, 3), unit="D", freq="3D"),
pd.tseries.offsets.MonthEnd(3),
pd.Index(pd.tseries.offsets.Day(day) for day in range(3)),
# we also support pd.Timedelta, but it does not have freqstr so we
# cannot automatically infer the unit during testing
# pd.Timedelta(days=3, freq="D"),
]
@pytest.mark.parametrize("duration", DURATIONS)
def test_coerce_duration_to_int(duration):
"""Test coercion of duration to int."""
ret = _coerce_duration_to_int(duration, freq=_get_freq(duration))
# check output type is always integer
assert type(ret) in (pd.Int64Index, np.integer, int)
# check result
if isinstance(duration, pd.Index):
np.testing.assert_array_equal(ret, range(3))
if isinstance(duration, pd.tseries.offsets.BaseOffset):
assert ret == 3
@pytest.mark.parametrize("n_timepoints", [3, 5])
@pytest.mark.parametrize("index_type", INDEX_TYPE_LOOKUP.keys())
def test_get_duration(n_timepoints, index_type):
"""Test getting of duration."""
index = _make_index(n_timepoints, index_type)
duration = _get_duration(index)
# check output type is duration type
assert isinstance(
duration, (pd.Timedelta, pd.tseries.offsets.BaseOffset, int, np.integer)
)
# check integer output
duration = _get_duration(index, coerce_to_int=True)
assert isinstance(duration, (int, np.integer))
assert duration == n_timepoints - 1
|
import logging
import sys
import traceback
from pycollisionavoidance.raycast.Point import LineSegment, Dot
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler('/tmp/walkgen.log')
handler.setLevel(logging.ERROR)
formatter = logging.Formatter('%(levelname)-8s-[%(filename)s:%(lineno)d]-%(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
class Obstacle:
"""
This class implements the defining Obstacles
"""
def __init__(self, id, corner_points, obstacle_shape, obstacle_type, description=""):
"""
Initialization of obstacle
:param id: obstacle ID
:param corner_points: corner coordinate points of obstacle mentioned in a cyclic order
:param obstacle_shape: shape of the obstacle
:param obstacle_type: type of the obstacle. Obstacle can be line , polygon
:param description: Description about the obstacle
"""
try:
assert type(corner_points) == tuple, "Corner point list must be a list of Points"
self.id = id
self.num_of_points = len(corner_points)
self.corner_points = corner_points
self.description = description
self.shape = obstacle_shape
self.type = obstacle_type
self.line_segments = []
# add segments of the obstacle based on the shape of the obstacle
if obstacle_shape == 'polygon':
for i in range(0, self.num_of_points - 1):
self.line_segments.append(LineSegment(point1=corner_points[i],
point2=corner_points[i + 1],
description=self.description))
self.line_segments.append(LineSegment(point1=corner_points[self.num_of_points - 1],
point2=corner_points[0],
description=self.description))
if obstacle_shape == 'line':
self.line_segments.append(LineSegment(point1=corner_points[0],
point2=corner_points[1],
description=self.description))
except AssertionError as e:
logging.critical(e)
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.critical(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
sys.exit()
except ValueError as e:
logging.critical(e)
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.critical(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
sys.exit()
except Exception as e:
logging.critical(e)
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.critical(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
sys.exit()
def update(self, corner_points, shape=None):
"""
Update coordinate of the obstacle.
:param corner_points: corner coordinate points of obstacle mentioned in a cyclic order
:param shape: shape of the obstacle (optional). No need to mention if shape of the obstacle has not changed
:return:
"""
try:
assert type(corner_points) == tuple, "Corner point list must be a list of Points"
self.corner_points = corner_points
self.num_of_points = len(corner_points)
if shape is not None:
self.shape = shape
self.line_segments.clear()
if self.shape == 'polygon':
for i in range(0, self.num_of_points - 1):
self.line_segments.append(LineSegment(point1=corner_points[i], point2=corner_points[i + 1]))
self.line_segments.append(
LineSegment(point1=corner_points[self.num_of_points - 1], point2=corner_points[0],
description=self.description))
elif self.shape == 'line':
self.line_segments.append(
LineSegment(point1=corner_points[0], point2=corner_points[1], description=self.description))
else:
self.line_segments.append(
LineSegment(point1=corner_points[0], point2=corner_points[0], description=self.description))
except AssertionError as e:
logging.critical(e)
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.critical(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
sys.exit()
except ValueError as e:
logging.critical(e)
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.critical(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
sys.exit()
except Exception as e:
logging.critical(e)
exc_type, exc_value, exc_traceback = sys.exc_info()
logging.critical(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
sys.exit()
|
<filename>ML_functions.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 2020
@author: <NAME>
"""
import numpy as np
import joblib
import pickle
from scipy import linalg
from scipy import sparse
import pyfftw
def create_HP_filt(flength,cutoff,TR):
cut=cutoff/TR
sigN2=(cut/np.sqrt(2))**2
K=linalg.toeplitz(1/np.sqrt(2*np.pi*sigN2)*np.exp(-np.linspace(0,flength,flength)**2/(2*sigN2)))
K=sparse.spdiags(1/np.sum(K,axis=0),0,flength,flength)*K
H=np.zeros([flength,flength])
X=np.array([np.ones(flength), range(1,flength+1)])
X=np.transpose(X)
for i in range(flength):
W=np.diag(K[i])
Hat=np.dot(np.dot(X,linalg.pinv(np.dot(W,X))),W)
H[i]=Hat[i]
HPfilt=np.eye(flength)-H
return HPfilt
def calc_cmro2(images_dict,d_phys,d_scan_par,d_analysis):
print('pre-processing ASL and BOLD data')
#scale echo1 1 data by M0 and threshold out low M0 values (also scale by 100)
x_axis,y_axis,no_slices,datapoints=np.shape(images_dict['echo1_data'])
image_data=np.zeros([x_axis,y_axis,no_slices,datapoints])
for i in range(datapoints):
with np.errstate(divide='ignore',invalid='ignore'):
image_data[:,:,:,i]=100*(np.divide(images_dict['echo1_data'][:,:,:,i],images_dict['M0_data']))
image_data[:,:,:,i][images_dict['M0_data']<d_analysis['M0_cut']]=0
flow_data=np.empty([x_axis,y_axis,no_slices,datapoints-2]) # pre-allocate array
# matrix surround subtraction for both c-(t0+t2)/2 and t+(c0+c2) to get perfusion data
# for even data points
flow_data=image_data[:,:,:,1:-1]-(image_data[:,:,:,0:-2]+image_data[:,:,:,2:])/2
# for odd data points
flow_odd=-image_data[:,:,:,1:-1]+(image_data[:,:,:,0:-2]+image_data[:,:,:,2:])/2
# add in odd data points
flow_data[:,:,:,1::2]=flow_odd[:,:,:,1::2]
# surround average to get BOLD data
bold_data=(images_dict['echo2_data'][:,:,:,1:-1]+(images_dict['echo2_data'][:,:,:,0:-2]+images_dict['echo2_data'][:,:,:,2:])/2)/2
# mask BOLD data (should make dimensinality reduction work better - apart from divide by zero problems)
for i in range(datapoints-2):
bold_data[:,:,:,i][images_dict['M0_data']<d_analysis['M0_cut']]=0
# convert into percent signal change
per_bold=np.empty([x_axis,y_axis,no_slices,datapoints-2]) # pre-allocate array
baseline=np.mean(bold_data[:,:,:,0:4],axis=3)
for i in range(datapoints-2):
with np.errstate(divide='ignore', invalid='ignore'):
per_bold[:,:,:,i]=np.divide(bold_data[:,:,:,i],baseline)
per_bold[:,:,:,i][baseline==0]=0
per_bold=(per_bold-1)
cut=300;
HPfilt=create_HP_filt(117,cut,4.4)
# HP filter data
print('HP filt BOLD data')
for i in range(x_axis):
for j in range(y_axis):
for k in range(no_slices):
per_bold[i,j,k,:]=per_bold[i,j,k,:]-np.mean(per_bold[i,j,k,0:4])
per_bold[i,j,k,:]=np.dot(HPfilt,per_bold[i,j,k,:])
per_bold[i,j,k,:]=per_bold[i,j,k,:]-np.mean(per_bold[i,j,k,0:4])
per_bold=np.nan_to_num(per_bold)
print('pyfftw FFT')
#
# calculate the FFT of BOLD and ASL data
# FFTW is faster than numpy fft so use this.
# import pre-computed fftw wisdom for these datasets for significant speed-up
# fft_wisdom=pickle.load(open('fft_wisdom.sav', 'rb'))
# pyfftw.import_wisdom(fft_wisdom)
pyfftw.interfaces.cache.enable()
BOLD_fft=pyfftw.interfaces.numpy_fft.fft(per_bold)
ASL_fft=pyfftw.interfaces.numpy_fft.fft(flow_data)
# Now calculate CBF0
print('predicting CBF0')
PLD_vect=np.linspace(d_scan_par['PLD'],d_scan_par['PLD']+no_slices*d_scan_par['slice_delay'], num=no_slices)
PLD_mat=np.tile(PLD_vect, (x_axis,y_axis,1))
array_elements=15
ML_array=np.empty([x_axis,y_axis,no_slices,3+2*array_elements])
ML_array[:,:,:,0]=d_phys['Hb']
ML_array[:,:,:,1]=d_phys['CaO20']
ML_array[:,:,:,2]=PLD_mat
ML_array[:,:,:,3:3+array_elements]=np.absolute(ASL_fft[:,:,:,0:array_elements])
ML_array[:,:,:,3+array_elements:3+2*array_elements]=np.absolute(BOLD_fft[:,:,:,0:array_elements])
ML_array=np.reshape(ML_array,(x_axis*y_axis*no_slices, 3+2*array_elements))
filename='CBF0_lightGBM_no_noise_50K_model.pkl'
net=joblib.load(filename)
filename='CBF0_lightGBM_no_noise_50K_scaler.pkl'
scaler=joblib.load(filename)
X_train_scaled=scaler.transform(ML_array)
CBF0_vect=net.predict(X_train_scaled)*150
CBF0=np.reshape(CBF0_vect, (x_axis,y_axis,no_slices))
CBF0[CBF0<0]=0
CBF0[CBF0>250]=250
CBF0[images_dict['M0_data']<d_analysis['M0_cut']]=0
array_elements=15
ML_array=np.empty([x_axis,y_axis,no_slices,3+2*array_elements -1])
ML_array[:,:,:,0]=d_phys['Hb']
ML_array[:,:,:,1]=d_phys['CaO20']
ML_array[:,:,:,2]=PLD_mat
ML_array[:,:,:,3:3+array_elements]=np.absolute(ASL_fft[:,:,:,0:array_elements])
ML_array[:,:,:,3+array_elements:3+2*array_elements - 1]=np.absolute(BOLD_fft[:,:,:,1:array_elements])
ML_array=np.reshape(ML_array,(x_axis*y_axis*no_slices, 3+2*array_elements -1))
print('Calculating CBF tSNR')
CBFsd=np.copy(CBF0)
CBFmean=np.copy(CBF0)
CBFsd=np.std(flow_data[:,:,:,0:20],axis=3)
CBFmean=np.mean(flow_data[:,:,:,0:20],axis=3)
CBFsd[CBF0<60]=np.nan
CBFmean[CBF0<60]=np.nan
print('ASL tSNR')
print(np.nanmean( np.divide(CBFmean, CBFsd) ))
print('Calculating BOLD tSNR')
BOLDsd=np.copy(CBF0)
BOLDmean=np.copy(CBF0)
BOLDsd=np.std(bold_data[:,:,:,0:20],axis=3)
BOLDmean=np.mean(bold_data[:,:,:,0:20],axis=3)
BOLDsd[CBF0<60]=np.nan
BOLDmean[CBF0<60]=np.nan
print('BOLD tSNR')
print(np.nanmean( np.divide(BOLDmean, BOLDsd) ))
print('predicting OEF')
# ensemble fitting
import os
scriptDirectory = os.path.dirname(os.path.abspath(__file__))
ensembleDirectory=os.path.join(scriptDirectory, 'OEF_ensemble_sav/')
file_list=os.listdir(ensembleDirectory)
OEF_array=np.zeros([x_axis,y_axis,no_slices,int(len(file_list)/2)])
array_counter=-1
for i in range(len(file_list)):
current_file=file_list[i]
if current_file[-9:-4]=='model':
filename='OEF_ensemble_sav/' + current_file
print(filename)
net=joblib.load(filename)
filename='OEF_ensemble_sav/' + current_file[0:-9] + 'scaler.pkl'
scaler=joblib.load(filename)
X_train_scaled=scaler.transform(ML_array)
# use CMRO2 regressor
CMRO2_vect=net.predict(X_train_scaled)*500
with np.errstate(divide='ignore',invalid='ignore'):
OEF_vect = np.divide ( CMRO2_vect , (d_phys['CaO20']*39.34*CBF0_vect) )
# OEF_vect= net.predict(X_train_scaled)
OEF_local=np.reshape(OEF_vect, (x_axis,y_axis,no_slices))
array_counter+=1
print(array_counter)
OEF_array[:,:,:,array_counter]=OEF_local
OEF_array[np.isnan(OEF_array)]=0
OEF_array[np.isinf(OEF_array)]=0
OEF=np.mean(OEF_array,3)
# limit impossible answers
OEF[OEF>=1]=1
OEF[OEF<0]=0
# calculate CMRO2
OEF[images_dict['M0_data']<d_analysis['M0_cut']]=0
CMRO2=OEF*39.34*d_phys['CaO20']*CBF0
# rational equation solution from CBF0 and CMRO2 to M (estimate with R^2=0.9)
# with np.errstate(divide='ignore',invalid='ignore'):
# M = (-0.04823*CMRO2 + 0.01983*CMRO2*CMRO2) / (29.19*CBF0 + 0.9426*CBF0*CBF0)
with np.errstate(divide='ignore',invalid='ignore'):
M = (8.532*CMRO2 + 2.19*CMRO2*CMRO2) / (4167*CBF0 + 25.82*CBF0*CBF0)
M[images_dict['M0_data']<d_analysis['M0_cut']]=0
# calculate Dc, O2 diffusivity from CBF0 and M (R^2 = 0.88 and RMSE = 0.33)
Dc=0.1728 + 0.03024*CBF0 + 8.4*M - 0.0003404*CBF0*CBF0 + 1.101*CBF0*M - 36.44*M*M +4.559E-6*CBF0*CBF0*CBF0 -0.01734*CBF0*CBF0*M - 1.725*CBF0*M*M - 1.755E-8*CBF0*CBF0*CBF0*CBF0 + 6.407E-5*CBF0*CBF0*CBF0*M + 0.03734*CBF0*CBF0*M*M
Dc[images_dict['M0_data']<d_analysis['M0_cut']]=0
return CMRO2, CBF0, OEF, M, Dc
|
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
AUTHOR = 'Spoony'
SITENAME = 'Full Stack Troubles'
SITESUBTITLE = 'Notes and descriptions in my day by day job issues'
SITEURL = ''
PATH = 'content'
DEFAULT_DATE = 'fs'
TIMEZONE = 'Europe/Madrid'
DEFAULT_LANG = 'en'
# Feed generation is usually not desired when developing
FEED_ALL_ATOM = None
CATEGORY_FEED_ATOM = None
TRANSLATION_FEED_ATOM = None
AUTHOR_FEED_ATOM = None
AUTHOR_FEED_RSS = None
# Blogroll
LINKS = (('Pelican', 'http://getpelican.com/'),
('Python.org', 'http://python.org/'),
('Jinja2', 'http://jinja.pocoo.org/'),
('You can modify those links in your config file', '#'),)
# Social widget
SOCIAL = (('You can add links in your config file', '#'),
('Another social link', '#'),)
DEFAULT_PAGINATION = 3
PAGINATION_PATTERNS = (
(1, '{base_name}/', '{base_name}/index.html'),
(2, '{base_name}/page/{number}/', '{base_name}/page/{number}/index.html'),
)
STATIC_PATHS = ['assets']
EXTRA_PATH_METADATA = {
'assets/robots.txt': {'path': 'robots.txt'},
'assets/favicon.ico': {'path': 'favicon.ico'},
'assets/CNAME': {'path': 'CNAME'}
}
# Post and Pages path
ARTICLE_PATHS = ['articles']
ARTICLE_URL = 'articles/{slug}.html'
ARTICLE_LANG_URL = 'articles/{slug}-{lang}.html'
ARTICLE_SAVE_AS = 'articles/{slug}.html'
ARTICLE_LANG_SAVE_AS = 'articles/{slug}-{lang}.html'
PAGE_URL = 'pages/{slug}/'
PAGE_SAVE_AS = 'pages/{slug}/index.html'
YEAR_ARCHIVE_SAVE_AS = '{date:%Y}/index.html'
MONTH_ARCHIVE_SAVE_AS = '{date:%Y}/{date:%m}/index.html'
# Tags and Category path
CATEGORY_URL = 'category/{slug}'
CATEGORY_SAVE_AS = 'category/{slug}/index.html'
CATEGORIES_SAVE_AS = 'catgegories.html'
TAG_URL = 'tag/{slug}'
TAG_SAVE_AS = 'tag/{slug}/index.html'
TAGS_SAVE_AS = 'tags.html'
# Author
AUTHOR_URL = 'author/{slug}'
AUTHOR_SAVE_AS = 'author/{slug}/index.html'
AUTHORS_SAVE_AS = 'authors.html'
# Plugins
PLUGIN_PATHS = [
'plugins'
]
PLUGINS = [
'i18n_subsites',
'sitemap',
'neighbors',
'assets'
]
# Sitemap
SITEMAP = {
'format': 'xml',
'priorities': {
'articles': 0.5,
'indexes': 0.5,
'pages': 0.5
},
'changefreqs': {
'articles': 'monthly',
'indexes': 'daily',
'pages': 'monthly'
}
}
I18N_SUBSITES = {
'es': {
'SITENAME': 'Tormentos Full Stack',
'LOCALE': 'es_ES',
# 'THEME': 'theme_en'
},
}
LANGUAGES_LOOKUP = {
'en': 'English',
'es': 'Español',
}
def lookup_lang_name(lang_code):
""" Lookup for language code function """
return LANGUAGES_LOOKUP[lang_code]
def my_ordered_items(item_d):
""" Sorting items function """
items = list(item_d.items())
# swap first and last using tuple unpacking
items[0], items[-1] = items[-1], items[0]
return items
JINJA_FILTERS = {
'lookup_lang_name': lookup_lang_name,
'my_ordered_items': my_ordered_items,
}
JINJA_ENVIRONMENT = {
'extensions' : ['jinja2.ext.i18n']
}
THEME = 'theme'
# Theme specific settings
# This is deprecated. Will be removed in future releases.
# Work around will be use HOME_COVER and use cover in individual articles.
# HEADER_COVER = 'https://casper.ghost.org/v1.0.0/images/welcome.jpg'
# This is deprecated. Will be removed in future releases.
# Work around will be use HOME_COLOR and use color in individual articles.
# HEADER_COLOR = 'black'
# To set background image for the home page.
# Theme specific settings
# This is deprecated. Will be removed in future releases.
# Work around will be use HOME_COVER and use cover in individual articles.
# HEADER_COVER = 'https://casper.ghost.org/v1.0.0/images/welcome.jpg'
# This is deprecated. Will be removed in future releases.
# Work around will be use HOME_COLOR and use color in individual articles.
# HEADER_COLOR = 'black'
# To set background image for the home page.
HEADER_COVER = 'assets/images/bombilla.jpg'
HEADER_COVERS_BY_TAG = {
'cupcake': 'assets/images/rainbow_cupcake_cover.png',
'general': 'https://casper.ghost.org/v1.0.0/images/writing.jpg'
}
HOME_COVER = 'https://casper.ghost.org/v1.0.0/images/welcome.jpg'
# SITE_LOGO = 'assets/images/skull.png'
AUTHORS_BIO = {
"spoony": {
"name": "<NAME>",
"cover": "assets/images/writing_machine.jpg",
"image": "assets/images/skull.png",
"website": "http://blog.spoonsdevs.com",
"linkedin": "antonio-mas-6953a821",
"github": "amr390",
"location": "Spain",
"bio": "Software Engineer since 2004, tech addict, proud father and curious in general"
}
}
# Uncomment following line if you want document-relative URLs when developing
# RELATIVE_URLS = True
|
#!/usr/bin/env python3
import os
import sys
from datetime import datetime, timedelta
from math import acos, sin, cos, radians
from operator import attrgetter
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
from shutil import copyfile
class ImageMeta():
def __init__(self, file_path, file_dir, file_name, file_extension):
'''extract file info from path and collect other data from exif'''
# image data
self.path = file_path
self.dir = file_dir
self.name = file_name
self.type = file_extension
self.extract_data()
self.get_datetime()
if not getattr(self, "coords", None):
self.place = "unknown"
# grouping data
self.grouping_factors = []
def extract_data(self):
'''extracting image exif and size data'''
exif_data = {}
with Image.open(self.path) as im:
info = im._getexif()
self.size = im.size
if info:
for tag, value in info.items(): # decoding exif data
decoded = TAGS.get(tag, tag)
if decoded == "GPSInfo":
gps_data = {} # creating a sub-dictionary of gps info
for t in value:
sub_decoded = GPSTAGS.get(t, t)
gps_data[sub_decoded] = value[t]
exif_data[decoded] = gps_data
if gps_data: # creating attribute "coords" from EXIF GPS data
lat_d, lat_m, lat_s = [int(value) for value in gps_data["GPSLatitude"]]
lat_sign = gps_data["GPSLatitudeRef"]
lat = (lat_d + lat_m/60 + lat_s/3600) * (1 - 2*(lat_sign == "S"))
long_d, long_m, long_s = [int(value) for value in gps_data["GPSLongitude"]]
long_sign = gps_data["GPSLongitudeRef"]
long = (long_d + long_m/60 + long_s/3600) * (1 - 2*(long_sign == "W"))
self.coords = (lat, long)
else:
exif_data[decoded] = value
self.exif = exif_data
def get_datetime(self):
'''Try to get creation date from exif or fallback to ctime. Return a datetime object'''
created = datetime.fromtimestamp(os.path.getctime(self.path))
datetime_str = self.exif.get("DateTime", None)
if datetime_str:
created = datetime.strptime(datetime_str, "%Y:%m:%d %H:%M:%S")
self.created = created
def grouping_dir(self, sub_dir):
'''returns a group subdirectory to which image should be copied'''
grouping_dir = os.path.join(self.dir, sub_dir)
for factor in self.grouping_factors:
if factor == "unknown":
break
grouping_dir = os.path.join(grouping_dir, str(factor))
return grouping_dir, self.name
def make_copy(self, sub_dir):
'''Copy image into provided directory'''
destination_dir, file_name = self.grouping_dir(sub_dir)
if not os.path.isdir(destination_dir):
os.makedirs(destination_dir)
destination = os.path.join(destination_dir, file_name)
if self.path != destination:
copyfile(self.path, destination)
class Place():
counter = 0
def __init__(self, img, images):
self.id = Place.counter
Place.counter += 1
self.name = str(self.id)
self.check_images(img, images)
def check_images(self, img_1, images):
'''Go through all other images and check if they can be assigned this Place'''
for img_2 in images:
if not getattr(img_2, "place", None):
if self.get_distance(img_1, img_2) <= 200: # DISTANCE IN METERS
img_2.place = self
def get_distance(self, img_1, img_2):
'''Calculate geographical distance (in meters) between two images'''
if not getattr(img_1, "coords", None) or not getattr(img_2, "coords", None):
return -1
lat1, long1 = map(radians, img_1.coords)
lat2, long2 = map(radians, img_2.coords)
d_long = abs(long1 - long2)
if (lat1, long1) == (lat2, long2):
return 0 # else acos may end up > 1 and throw error
R = 6371000 # Appx. Earth radius in meters
# Spherical Law of Cosines formula
dist = acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(d_long)) * R
return dist
class Timespace():
'''time span object to separate photos from the same place some time apart'''
def __init__(self, img_src, images):
self.place = img_src.place
self.check_images(img_src, images)
img_src.timespace = self
def check_images(self, img_src, images):
'''checks all the images if they can be assigned to this timespace
if so updates self start/end and assigns itself to given image'''
starts = img_src.created
ends = img_src.created
for img in images:
if img.place == self.place:
if img.created >= starts and img.created <= ends:
img.timespace = self
elif img.created >= starts - timedelta(days=3) and img.created < starts:
starts = img.created
img.timespace = self
elif img.created <= ends + timedelta(days=3) and img.created > ends:
ends = img.created
img.timespace = self
self.starts = starts
self.ends = ends
def getname(self):
'''returns name string consisting of place and start - end dates'''
sd, sm, sy = self.starts.strftime("%d %b %y").split()
ed, em, ey = self.ends.strftime("%d %b %y").split()
if sy == ey:
if sm == em:
if sd == ed:
date = ed + em + ey
else:
date = sd + "-" + ed + em + ey
else:
date = sd + sm + "-" + ed + em + ey
else:
date = sd + sm + sy + "-" + ed + em + ey
name = self.place.name + "_" + date
return name
def create_source_list(img_dir, valid_extensions):
'''Returning list of tuples representing images contained in the directory'''
if not os.path.isdir(img_dir):
sys.exit("Entered directory is not valid!")
source = []
files = os.listdir(img_dir)
for file_name in files:
file_path = os.path.join(img_dir, file_name)
f, file_extension = os.path.splitext(file_path)
if os.path.isdir(file_path):
continue # skip directories
if file_extension.lower() not in valid_extensions:
continue # skip files that do not have accepted extensions
source.append((file_path, img_dir, file_name, file_extension))
return source
def add_grouping_factor(images, factor):
'''Add a grouping factor to each instance of ImageMeta'''
if factor in ["year", "month", ("year", "month")]:
for img in images:
if factor == "year":
gf = (str(img.created.year), )
elif factor == "month":
gf = (img.created.strftime("%B"), )
elif factor == ("year", "month"):
gf = (str(img.created.year), img.created.strftime("%B"))
img.grouping_factors += gf
elif factor == "place":
for img in images:
if not getattr(img, "place", None):
Place(img, images)
gf = getattr(img.place, "name", "unknown")
img.grouping_factors.append(gf)
elif factor == ("place", "date"):
for img in images:
if not getattr(img, "place", None):
Place(img, images)
for img in images:
if img.place == "unknown":
img.timespace = "unknown"
else:
if not getattr(img, "timespace", None):
Timespace(img, images)
for img in images:
if img.place == "unknown":
continue
name = img.timespace.getname()
img.grouping_factors.append(name)
def create_subdir(img_dir):
'''Create unique imagine output directory each run'''
n = 0
while True:
sub_dir = "imagine{}".format(str(n).zfill(2))
abs_sub = os.path.join(img_dir, sub_dir)
if not os.path.isdir(abs_sub):
break
n += 1
return sub_dir
def main():
# create list of ImageMeta classes from given directory
valid_extensions = ('.jpg', '.jpeg')
if len(sys.argv) == 2:
img_dir = sys.argv[1]
source_list = create_source_list(img_dir, valid_extensions)
images = [ImageMeta(*file_data) for file_data in source_list]
images = sorted(images, key=attrgetter("created"))
else:
sys.exit("Correct input: 'python3 imagine.py <images_directory>'")
# prompt user about action to be taken with the images
actions = {
"1": "year",
"2": "month",
"3": ("year", "month"),
"4": "place",
"5": ("place", "date")
}
print("\nThere are {} images in {}".format(len(source_list), img_dir))
print("Here is what you can do with them:")
print("[1] Group by year")
print("[2] Group by month")
print("[3] Group by year and month")
print("[4] Group by places")
print("[5] Smart Grouping (place and date)")
print("[q] Quit")
while True:
users_choice = input("> ")
if users_choice in actions.keys():
add_grouping_factor(images, actions[users_choice])
subdir = create_subdir(img_dir)
for img in images:
img.make_copy(subdir)
break
elif users_choice.lower() == "q":
sys.exit("Goodbye!")
else:
print("Invalid input, try again.")
if __name__ == '__main__':
main()
|
################################################################################
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
##
## (C) Copyrights Dr. <NAME> and TSRI 2019
##
################################################################################
#############################################################################
#
# Author: <NAME>
#
# Copyright: <NAME> and TSRI 2019
#
#########################################################################
#
import os, sys, numpy, platform, datetime, tempfile, shutil, random, tarfile, pickle
from glob import glob
class runADCP:
def myprint(self, txt, newline=True):
sys.stdout.write(txt)
if newline:
sys.stdout.write('\n')
def myexit(self):
if self.targetFile is not None:
print "clean up unzipped map files"
try:
shutil.rmtree('./tmp_%s'%self.jobName)
except OSError:
pass
for element in ['C','A','SA','N','NA','OA','HD','d','e']:
if os.path.isfile('rigidReceptor.%s.map'%element):
os.remove('rigidReceptor.%s.map'%element)
if os.path.isfile('transpoints'):
os.remove('transpoints')
if os.path.isfile('translationPoints.npy'):
os.remove('translationPoints.npy')
if os.path.isfile('rigidReceptor.pdbqt'):
os.remove('rigidReceptor.pdbqt')
if os.path.isfile('con'):
os.remove('con')
sys.exit(0)
def __init__(self):
import multiprocessing
self.ncpu = multiprocessing.cpu_count()
import platform, subprocess
system_info = platform.uname()
_platform = system_info[0]
from ADFR.utils.MakeGrids import findBinary
if _platform == "Linux":
binaryName = "adcp_Linux-x86_64"
elif _platform == "Darwin":
binaryName = "adcp_Darwin"
else:
binaryName = "adcp_Win-x86_64"
binary = findBinary(binaryName)
assert binary is not None
self._ADFRpath = os.path.dirname(binary)
#print "_ADFRpath", self._ADFRpath, "cwd:", os.getcwd(), "binary" , binary, "_platform", _platform
if _platform == 'Windows':
self.shell=False
else:
self.shell=True
self._argv = ['%s/%s -t 2'%(self._ADFRpath, binaryName)]
# modify here
#cmd = os.path.join(os.path.abspath(ADFR.__path__[0]), 'bin', 'adcp')
#self._argv = ['/1tb/crankite_new/peptide -t 2']
self.completedJobs = 0
self.numberOfJobs = 0
self.outputBaseName = None # a folder with that name will be crated to store log files and ligands
# a _summary.dlg file will be create with this name too
# is specified using -o on the command line
self.jobName = 'NoName'
self.targetFile = None
def __call__(self, **kw):
#
# run ADFR GAs using the list of command line arguments from the sysargv list
#
import subprocess, datetime
dataDict = {}
seed = None
rncpu= None
nbRuns = 50
numSteps = 2500000
jobName = 'NoName'
partition = 0
skip = False
rncpu = kw.pop('maxCores')
if rncpu is None:
ncores = self.ncpu
self.myprint( 'Detected %d cores, using %d cores'%(self.ncpu, ncores))
else:
assert rncpu > 0, "ERROR: maxCores a positive number, got %d"%rncpu
ncores = min(self.ncpu, rncpu)
self.myprint( 'Detected %d cores, request %d cores, using %d cores'%(self.ncpu, rncpu, ncores))
if kw['nbRuns'] is not None:
self.nbRuns = nbRuns = kw.pop('nbRuns')
self.numberOfJobs = nbRuns
self._jobStatus = [None]*nbRuns
seed = kw.pop('seedValue')
if seed is None:
seed = str(random.randint(1,999999))
# check ramaprob.data file
foundData = False
if os.path.isfile("ramaprob.data"):
print "using ramaprob.data in current folder"
foundData = True
else:
from mglutil.util.packageFilePath import findFilePath
dataFile = findFilePath("ramaprob.data", "ADCP")
if dataFile:
cwd = os.getcwd()
print "copying the ramaprob.data file from %s to %s"%(dataFile, cwd)
shutil.copy(dataFile, cwd)
foundData = True
## elif os.path.isfile("%s/ramaprob.data"%self._ADFRpath):
## print "copying the ramaprob.data file"
## shutil.copy(os.path.join('%s/ramaprob.data'%self._ADFRpath),os.getcwd())
if not foundData:
print "ERROR: cannot find probability data for ramachandran plot"
self.myexit()
if kw['jobName'] is not None:
self.jobName = jobName = kw.pop('jobName')
# if target is zip file unzip and replace cmdline arguments
self.targetFile = targetFile = kw.pop('target')
if targetFile is None and not os.path.isfile("transpoints"):
print "ERROR: no receptor files found"
self.myexit()
# if transpoints file does not exists
elif targetFile is not None:
# unzip mapsFile
import zipfile
with zipfile.ZipFile(targetFile, 'r') as zip_ref:
zip_ref.extractall('./tmp_%s/'%jobName)
for element in ['C','A','SA','N','NA','OA','HD','d','e']:
try:
shutil.copy(os.path.join('./tmp_%s/'%jobName,targetFile[:-4],'rigidReceptor.%s.map'%element),os.getcwd())
except IOError:
print "WARNING: cannot locate map file for %s"%element
shutil.copy(os.path.join('./tmp_%s/'%jobName,targetFile[:-4],'translationPoints.npy'),os.getcwd())
shutil.copy(os.path.join('./tmp_%s/'%jobName,targetFile[:-4],'rigidReceptor.pdbqt'),os.getcwd())
ttt = numpy.load('translationPoints.npy')
fff = open('transpoints','w')
fff.write('%s\n'%len(ttt))
numpy.savetxt(fff,ttt,fmt='%7.3f')
fff.close()
else:
for element in ['C','A','SA','N','NA','OA','HD','d','e']:
if not os.path.isfile("rigidReceptor.%s.map"%element):
print "WARNING: cannot locate map file rigidReceptor.%s.map"%element
fff = open('constrains','w')
fff.write('1\n')
fff.close()
#print 'write constrains %s\n'%''.join(lines)
#check overwriting files
for i in range(nbRuns):
if os.path.isfile('%s_%d.pdb'%(jobName,i+1)):
if not kw['overwriteFiles']:
print "ERROR: output file exists %s_%d.pdb"%(jobName,i+1)
self.myexit()
else:
print "Warning: overwriting output file %s_%d.pdb"%(jobName,i+1)
self.dryRun = kw.pop('dryRun')
# build cmdline args for adcp binary
argv = self._argv
if kw['sequence'] is None:
if kw['input'] is None or kw['input'][-3:] != 'pdb':
print "ERROR: no input for peptide found"
self.myexit()
else:
argv.append('-f')
argv.append('%s'%kw['input'])
else:
if kw['partition'] is None:
argv.append('%s'%kw['sequence'])
else:
partition = kw['partition']
argv.append('%s'%kw['sequence'])
if partition < 0:
partition = 0
elif partition > 100:
partition = 100
# set up the length for each run, 25M as default
argv.append('-r')
if kw['numSteps'] is not None:
numSteps = kw['numSteps']
argv.append('1x%s'%numSteps)
# set up other options for ADCP
ADCPDefaultOptions = "-p Bias=NULL,external=5,constrains,1.0,1.0"
if kw['cyclic']:
ADCPDefaultOptions += ",external2=4,constrains,1.0,1.0"
if kw['cystein']:
ADCPDefaultOptions += ",SSbond=50,2.2,50,0.35"
ADCPDefaultOptions += ",Opt=1,0.25,0.75,0.0"
argv.append(ADCPDefaultOptions)
# add arguments that will be set during the loop submitting jobs
# for seed jubNum and outputName
argv.extend(['-s', '-1', '-o', jobName,' '])
jobs = {} # key will be process until process.poll() is not None (i.e. finished)
from time import time, sleep
t0 = time()
runStatus = [None]*(nbRuns)
runEnergies = [999.]*(nbRuns)
procToRun = {}
outfiles = {}
nbStart = 0 # number of started runs
nbDone = 0 # number of completed runs
self.myprint( "Performing search (%d ADCP runs with %d steps each) ..."%
(nbRuns, numSteps))
print "0% 10 20 30 40 50 60 70 80 90 100%"
print "|----|----|----|----|----|----|----|----|----|----|"
numHelix = nbRuns * partition / 100
# submit the first set of jobs
for jobNum in range(1,min(nbRuns,ncores)+1):
# overwrite seed
if seed == -1:
argv[-4] = str(random.randint(1,999999))
else:
argv[-4] = str(seed+jobNum-1)
# overwrite jobNum
argv[-2] = '%s_%d.pdb'%(jobName,jobNum)
# since we set shell=False on Windows, we cannot redirect output to a file
# like in the following commented out line. We will open a file "outfile"
# and set stdout to the file handle.
#argv[-1] = '> %s_%d.out 2>&1'%(jobName,jobNum)
# overwrite the sequence if parition is found
if partition > 0 and partition < 100 and kw['sequence'] is not None:
if jobNum <= numHelix:
argv[1] = kw['sequence'].upper()
else:
argv[1] = kw['sequence'].lower()
if self.dryRun:
print '/n*************** command ***************************\n'
print ' '.join(argv)
print
self.myexit()
outfile = open('%s_%d.out'%(jobName,jobNum), 'w')
#process = subprocess.Popen(' '.join(argv),
# stdout=subprocess.PIPE ,
# stderr=subprocess.PIPE,
# bufsize = 1, shell=self.shell, cwd=os.getcwd())
process = subprocess.Popen(' '.join(argv),
stdout=outfile,#subprocess.PIPE ,
stderr=outfile, #subprocess.PIPE,
bufsize = 1, shell=self.shell , cwd=os.getcwd())
procToRun[process] = jobNum-1
outfiles[jobNum] = outfile # process.stdout returns None. So save the file handle in the dictionary, so that we can close the file after the job finishes
nbStart += 1
# check for completion and start new runs until we are done
while nbDone < nbRuns:
# check running processes
for proc, jnum in procToRun.items():
#import pdb;pdb.set_trace()
if proc.poll() is not None: # process finished
if proc.returncode !=0:
runStatus[jnum] = ('Error', '%s%04d'%(jobName, jnum+1))
error = '\n'.join(runStatus[jnum][1])
status = 'FAILED'
self.myprint( '%d ENDED WITH ERROR'%(jnum,))
print '%d err'%jnum
else:
status = 'OK'
error = ''
runStatus[jnum] = ('OKAY', '%s%04d'%(jobName, jnum+1))
#self.myprint( jnum, 'ENDED OK')
#print '%d ok'%jnum
#import pdb;pdb.set_trace()
#f = open('%s_%d.out'%(jobName,jnum+1))
f = outfiles[jnum+1] # the file should still be open
if not f.closed:
f.close()
f = open('%s_%d.out'%(jobName,jnum+1))
lines = f.readlines()
#print "Lines in %s_%d.out %d"%(jobName,jnum+1, len(lines))
f.close()
for ln in lines:
if ln.startswith('best target energy'):
runEnergies[jnum] = float(ln.rstrip().split()[3])
nbDone += 1
# remove process
del procToRun[proc]
self._jobStatus[jobNum-1] = 2
self.completedJobs += 1
percent = float(self.completedJobs)/self.numberOfJobs
sys.stdout.write('%s\r' % ('*'*int(50*percent)))
sys.stdout.flush()
if nbStart < nbRuns:
# start new one
jobNum += 1
if seed == -1:
argv[-4] = str(random.randint(1,999999))
else:
argv[-4] = str(seed+jobNum-1)
# overwrite jobNum
argv[-2] = '%s_%d.pdb'%(jobName,jobNum)
#argv[-1] = '> %s_%d.out 2>&1'%(jobName,jobNum)
outfileName = "%s_%d.out"%(jobName,jobNum)
# remove output file in case it exists
#try:
# os.remove(argv[-1])
#except OSError:
# pass
if os.path.exists(outfileName):
f = outfiles.get(jobNum, None)
if f and not f.closed:
f.close()
os.remove(outfileName)
outfile = open(outfileName, "w")
# overwrite the sequence if parition is found
if partition > 0 and partition < 100 and kw['sequence'] is not None:
if jobNum <= numHelix:
argv[1] = kw['sequence'].upper()
else:
argv[1] = kw['sequence'].lower()
#process = subprocess.Popen(' '.join(argv),
# stdout=subprocess.PIPE ,
# stderr=subprocess.PIPE,
# bufsize = 1, shell=self.shell, cwd=os.getcwd())
process = subprocess.Popen(' '.join(argv),
stdout=outfile, #subprocess.PIPE ,
stderr=outfile, #subprocess.PIPE,
bufsize = 1, shell=self.shell, cwd=os.getcwd())
procToRun[process] = jobNum-1
outfiles[jobNum] = outfile
nbStart += 1
sleep(1)
dt = time()-t0
h,m,s = str(datetime.timedelta(seconds=dt)).split(':')
self.myprint( 'Docking performed in %.2f seconds, i.e. %s hours %s minutes %s seconds '%(dt, h, m, s))
sort_index = numpy.argsort(runEnergies)
try:
from MolKit2.AARotamer import AARotamer, CanonicalAARotamers, AARotamerMutator
except ImportError:
#write out energy for top 5 solutions and exit
for i in range(min(5,nbRuns)):
self.myprint('No. %d energy found is %3.1f kcal/mol at %s_%d.pdb '%(i+1, runEnergies[sort_index[i]]*0.59219, jobName, sort_index[i]+1))
self.myexit()
kw['input'] = "%s.pdb"%jobName
kw['rec'] = 'rigidReceptor.pdbqt'
#import shutil
with open("%s.pdb"%jobName, 'wb') as outFile:
for i in range(nbRuns):
if runEnergies[i] < runEnergies[sort_index[0]] + 20:
with open("%s_%d.pdb"%(jobName,i+1), 'rb') as com:
shutil.copyfileobj(com, outFile)
from clusterADCP import clusterADCP
runner = clusterADCP()
runner(**kw)
self.myexit()
if __name__=='__main__':
#from ADFR.utils.runADFR import runADFR
#from ADFR.utils.optParser import ArgParser
import argparse
parser = argparse.ArgumentParser(description='AutoDock CrankPep',
usage="usage: python %(prog)s -s GaRyMiChEL -t rec.trg -o output",
version="%prog 0.1")
parser.add_argument("-s", "--sequence",dest="sequence",
help="initialize peptide from sequence, lower case for coil and UPPER case for helix")
parser.add_argument("-p", "--partition",dest="partition",type=int,
help="partition for starting from a mixture of helix/coil conformation, percentage(helix)=partition/100 note this option will overwrite the CaSe in sequence")
parser.add_argument("-i", "--input",dest="input",
help="use conformation from pdb file as input")
parser.add_argument("-t", "--target",dest="target",
help="a zipped file prepared with AGFR describing the receptor")
parser.add_argument("-n", "--numSteps", type=int,
default=2500000, dest="numSteps", help='max step for one replica')
parser.add_argument("-N", "--nbRuns", type=int,
default=50, dest="nbRuns", help='number of replicas')
parser.add_argument("-c", "--maxCores", type=int, dest="maxCores")
parser.add_argument("-o", "--jobName",dest="jobName")
parser.add_argument(
'-y', "--dryRun", dest="dryRun", action="store_true",
default=False,
help="print the first adcp command line and exit")
parser.add_argument(
'-cyc', "--cyclic", dest="cyclic", action="store_true",
default=False,
help="option for cyclic peptide through backbone")
parser.add_argument(
'-cys', "--cystein", dest="cystein", action="store_true",
default=False,
help="option for cyclic peptide through CYS-S-S-CYS")
parser.add_argument(
'-O', "--overwriteFiles", dest="overwriteFiles",
action="store_true", default=False,
help="overwrite existing output files silently")
parser.add_argument(
'-S', "--seed", dest="seedValue", type=int, default=-1,
help="seed for random number generator")
parser.add_argument("-nc", "--natContacts", type=float,
dest="nc", help='native contacts cutoff used in the clustering')
parser.add_argument("-rmsd", "--rmsd", type=float,
dest="rmsd", help='backbone rmsd cutoff used in the clustering')
parser.add_argument("-ref", "--ref",dest="ref", help='reference peptide structure for calculating rmsd and fnc')
kw = vars(parser.parse_args())
runner = runADCP()
runner(**kw)
|
<gh_stars>0
"""
Test epsagon init
"""
import mock
import epsagon
import os
from imp import reload
from epsagon.trace_transports import HTTPTransport
@mock.patch('epsagon.patcher.patch_all')
@mock.patch('os.getenv', side_effect=(lambda x: {
'EPSAGON_HANDLER': None,
'DISABLE_EPSAGON': 'FALSE',
'DISABLE_EPSAGON_PATCH': 'FALSE',
}[x]))
def test_epsagon(wrapped_get, wrapped_patch):
reload(epsagon)
wrapped_get.assert_has_calls([
mock.call('DISABLE_EPSAGON'),
mock.call('DISABLE_EPSAGON_PATCH'),
])
wrapped_patch.assert_called()
@mock.patch('epsagon.patcher.patch_all')
@mock.patch('os.getenv', side_effect=(lambda x: {
'EPSAGON_HANDLER': None,
'DISABLE_EPSAGON': 'FALSE',
'DISABLE_EPSAGON_PATCH': 'TRUE',
}[x]))
def test_epsagon_no_patch_env(wrapped_get, wrapped_patch):
reload(epsagon)
wrapped_get.assert_has_calls([
mock.call('DISABLE_EPSAGON'),
mock.call('DISABLE_EPSAGON_PATCH'),
])
wrapped_patch.assert_not_called()
@mock.patch('epsagon.patcher.patch_all')
@mock.patch('os.getenv', side_effect=(lambda x: {
'EPSAGON_HANDLER': None,
'DISABLE_EPSAGON': 'TRUE',
'DISABLE_EPSAGON_PATCH': 'TRUE',
}[x]))
def test_epsagon_disable_epsagon_and_disable_patch(wrapped_get, wrapped_patch):
reload(epsagon)
wrapped_get.assert_has_calls([
mock.call('DISABLE_EPSAGON'),
mock.call('DISABLE_EPSAGON_PATCH'),
])
wrapped_patch.assert_not_called()
assert os.environ['DISABLE_EPSAGON_PATCH'] == 'TRUE'
def dummy():
return True
assert epsagon.lambda_wrapper(dummy) is dummy
assert epsagon.step_lambda_wrapper(dummy) is dummy
assert epsagon.azure_wrapper(dummy) is dummy
assert epsagon.python_wrapper(dummy) is dummy
assert epsagon.gcp_wrapper(dummy) is dummy
@mock.patch('os.getenv', side_effect=(lambda x: {
'EPSAGON_HANDLER': 'epsagon.lambda_wrapper',
'DISABLE_EPSAGON': 'FALSE',
'DISABLE_EPSAGON_PATCH': 'FALSE',
'EPSAGON_SSL': 'FALSE',
'EPSAGON_TOKEN': 'FALSE',
'EPSAGON_APP_NAME': 'FALSE',
'EPSAGON_COLLECTOR_URL': 'FALSE',
'EPSAGON_METADATA': 'FALSE',
'EPSAGON_DISABLE_ON_TIMEOUT': 'FALSE',
'EPSAGON_DEBUG': 'FALSE',
'EPSAGON_SEND_TRACE_ON_ERROR': 'FALSE',
'EPSAGON_URLS_TO_IGNORE': '',
'EPSAGON_ENDPOINTS_TO_IGNORE': '',
'EPSAGON_IGNORED_KEYS': '',
'EPSAGON_ALLOWED_KEYS': '',
'EPSAGON_STEPS_OUTPUT_PATH': '',
}[x]))
def test_epsagon_wrapper_env_init(wrapped_get):
reload(epsagon)
epsagon.init()
wrapped_get.assert_has_calls([
mock.call('EPSAGON_HANDLER'),
mock.call('EPSAGON_SSL'),
mock.call('EPSAGON_URLS_TO_IGNORE'),
mock.call('EPSAGON_ENDPOINTS_TO_IGNORE'),
mock.call('EPSAGON_IGNORED_KEYS'),
mock.call('EPSAGON_ALLOWED_KEYS'),
mock.call('EPSAGON_TOKEN'),
mock.call('EPSAGON_APP_NAME'),
mock.call('EPSAGON_COLLECTOR_URL'),
mock.call('EPSAGON_METADATA'),
mock.call('EPSAGON_DISABLE_ON_TIMEOUT'),
mock.call('EPSAGON_DEBUG'),
mock.call('EPSAGON_SEND_TRACE_ON_ERROR'),
mock.call('EPSAGON_HANDLER'),
mock.call('DISABLE_EPSAGON'),
mock.call('DISABLE_EPSAGON_PATCH'),
mock.call('EPSAGON_SSL'),
mock.call('EPSAGON_URLS_TO_IGNORE'),
mock.call('EPSAGON_ENDPOINTS_TO_IGNORE'),
mock.call('EPSAGON_IGNORED_KEYS'),
mock.call('EPSAGON_ALLOWED_KEYS'),
mock.call('EPSAGON_STEPS_OUTPUT_PATH'),
mock.call('EPSAGON_TOKEN'),
mock.call('EPSAGON_APP_NAME'),
mock.call('EPSAGON_COLLECTOR_URL'),
mock.call('EPSAGON_METADATA'),
mock.call('EPSAGON_DISABLE_ON_TIMEOUT'),
mock.call('EPSAGON_DEBUG'),
mock.call('EPSAGON_SEND_TRACE_ON_ERROR'),
mock.call('EPSAGON_PROPAGATE_LAMBDA_ID')
])
default_http = HTTPTransport("epsagon", "1234")
@mock.patch('epsagon.utils.create_transport', side_effect=lambda x, y: default_http)
@mock.patch('epsagon.trace.TraceFactory.initialize')
@mock.patch('os.getenv', side_effect=(lambda x: {
'EPSAGON_HANDLER': 'epsagon.lambda_wrapper',
'DISABLE_EPSAGON': 'FALSE',
'DISABLE_EPSAGON_PATCH': 'FALSE',
'EPSAGON_SSL': 'FALSE',
'EPSAGON_TOKEN': '<PASSWORD>',
'EPSAGON_APP_NAME': 'test',
'EPSAGON_COLLECTOR_URL': 'epsagon',
'EPSAGON_METADATA': 'TRUE',
'EPSAGON_DISABLE_ON_TIMEOUT': 'FALSE',
'EPSAGON_DEBUG': 'FALSE',
'EPSAGON_SEND_TRACE_ON_ERROR': 'FALSE',
'EPSAGON_URLS_TO_IGNORE': '',
'EPSAGON_IGNORED_KEYS': '',
'EPSAGON_ALLOWED_KEYS': '',
'EPSAGON_LOG_TRANSPORT': 'FALSE',
'EPSAGON_ENDPOINTS_TO_IGNORE': '',
'EPSAGON_SPLIT_ON_SEND': 'FALSE',
'EPSAGON_PROPAGATE_LAMBDA_ID': 'FALSE',
'EPSAGON_LOGGING_TRACING_ENABLED': 'TRUE',
'AWS_LAMBDA_FUNCTION_NAME': None,
'EPSAGON_STEPS_OUTPUT_PATH': '',
'EPSAGON_SAMPLE_RATE': 0.5
}[x]))
def test_epsagon_wrapper_env_init(_wrapped_get, wrapped_init, _create):
reload(epsagon)
epsagon.init()
wrapped_init.assert_called_with(
app_name='test',
token='1234',
collector_url='epsagon',
metadata_only=True,
disable_timeout_send=False,
debug=False,
send_trace_only_on_error=False,
url_patterns_to_ignore=None,
keys_to_ignore=None,
keys_to_allow=None,
transport=default_http,
split_on_send=False,
propagate_lambda_id=False,
logging_tracing_enabled=True,
step_dict_output_path=None,
sample_rate=0.5,
)
@mock.patch('epsagon.http_filters.add_ignored_endpoints')
@mock.patch('os.getenv', side_effect=(lambda x: {
'EPSAGON_HANDLER': 'epsagon.lambda_wrapper',
'DISABLE_EPSAGON': 'FALSE',
'DISABLE_EPSAGON_PATCH': 'FALSE',
'EPSAGON_SSL': 'FALSE',
'EPSAGON_TOKEN': '1234',
'EPSAGON_APP_NAME': 'test',
'EPSAGON_COLLECTOR_URL': 'epsagon',
'EPSAGON_METADATA': 'TRUE',
'EPSAGON_DISABLE_ON_TIMEOUT': 'FALSE',
'EPSAGON_DEBUG': 'FALSE',
'EPSAGON_SEND_TRACE_ON_ERROR': 'FALSE',
'EPSAGON_URLS_TO_IGNORE': '',
'EPSAGON_IGNORED_KEYS': '',
'EPSAGON_ALLOWED_KEYS': '',
'EPSAGON_STEPS_OUTPUT_PATH': '',
'EPSAGON_ENDPOINTS_TO_IGNORE': '/health,/test',
'EPSAGON_LOG_TRANSPORT': 'FALSE',
'EPSAGON_SPLIT_ON_SEND': 'FALSE',
'EPSAGON_PROPAGATE_LAMBDA_ID': 'FALSE',
'EPSAGON_LOGGING_TRACING_ENABLED': 'TRUE',
'AWS_LAMBDA_FUNCTION_NAME': None,
'EPSAGON_SAMPLE_RATE': 0.5
}[x]))
def test_epsagon_wrapper_env_endpoints(_wrapped_get, wrapped_http):
reload(epsagon)
epsagon.init()
wrapped_http.assert_called_with(['/health', '/test'])
|
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
import json
import os
from textwrap import dedent
from pants.backend.core.register import build_file_aliases as register_core
from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.core.targets.resources import Resources
from pants.backend.jvm.register import build_file_aliases as register_jvm
from pants.backend.jvm.targets.jar_dependency import JarDependency
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.jvm.targets.java_tests import JavaTests
from pants.backend.jvm.targets.jvm_app import JvmApp
from pants.backend.jvm.targets.jvm_binary import JvmBinary
from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.backend.jvm.targets.scala_library import ScalaLibrary
from pants.backend.project_info.tasks.depmap import Depmap
from pants.backend.python.register import build_file_aliases as register_python
from pants.base.exceptions import TaskError
from pants_test.tasks.task_test_base import ConsoleTaskTestBase
class BaseDepmapTest(ConsoleTaskTestBase):
@classmethod
def task_type(cls):
return Depmap
class DepmapTest(BaseDepmapTest):
@property
def alias_groups(self):
return register_core().merge(register_jvm()).merge(register_python())
def setUp(self):
super(DepmapTest, self).setUp()
def add_to_build_file(path, name, type, deps=(), **kwargs):
self.add_to_build_file(path, dedent("""
{type}(name='{name}',
dependencies=[{deps}],
{extra}
)
""".format(
type=type,
name=name,
deps=','.join("pants('{0}')".format(dep) for dep in list(deps)),
extra=('' if not kwargs else ', '.join('{0}={1}'.format(k, v) for k, v in kwargs.items()))
)))
def create_python_binary_target(path, name, entry_point, type, deps=()):
self.add_to_build_file(path, dedent("""
{type}(name='{name}',
entry_point='{entry_point}',
dependencies=[{deps}]
)
""".format(
type=type,
entry_point=entry_point,
name=name,
deps=','.join("pants('{0}')".format(dep) for dep in list(deps)))
))
def create_jvm_app(path, name, type, binary, deps=()):
self.add_to_build_file(path, dedent("""
{type}(name='{name}',
dependencies=[pants('{binary}')],
bundles={deps}
)
""".format(
type=type,
name=name,
binary=binary,
deps=deps)
))
add_to_build_file('common/a', 'a', 'target')
add_to_build_file('common/b', 'b', 'jar_library')
self.add_to_build_file('common/c', dedent("""
java_library(name='c',
sources=[],
)
"""))
add_to_build_file('common/d', 'd', 'python_library')
create_python_binary_target('common/e', 'e', 'common.e.entry', 'python_binary')
add_to_build_file('common/f', 'f', 'jvm_binary')
add_to_build_file('common/g', 'g', 'jvm_binary', deps=['common/f:f'])
self.create_dir('common/h')
self.create_file('common/h/common.f')
create_jvm_app('common/h', 'h', 'jvm_app', 'common/f:f', "[bundle(fileset='common.f')]")
self.create_dir('common/i')
self.create_file('common/i/common.g')
create_jvm_app('common/i', 'i', 'jvm_app', 'common/g:g', "[bundle(fileset='common.g')]")
add_to_build_file('overlaps', 'one', 'jvm_binary', deps=['common/h', 'common/i'])
self.add_to_build_file('overlaps', dedent("""
java_library(name='two',
dependencies=[pants('overlaps:one')],
sources=[],
)
"""))
self.add_to_build_file('resources/a', dedent("""
resources(
name='a_resources',
sources=['a.resource']
)
"""))
self.add_to_build_file('src/java/a', dedent("""
java_library(
name='a_java',
resources=[pants('resources/a:a_resources')]
)
"""))
self.add_to_build_file('src/java/a', dedent("""
target(
name='a_dep',
dependencies=[pants(':a_java')]
)
"""))
self.add_to_build_file('src/java/b', dedent("""
java_library(
name='b_java',
dependencies=[':b_dep']
)
target(
name='b_dep',
dependencies=[':b_lib']
)
java_library(
name='b_lib',
sources=[],
)
"""))
# It makes no sense whatsoever to have a java_library that depends
# on a Python library, but we want to ensure that depmap handles
# cases like this anyway because there might be other cases which
# do make sense (e.g. things that generate generic resources)
self.add_to_build_file('src/java/java_depends_on_python', dedent("""
java_library(
name='java_depends_on_python',
dependencies=['common/d:d']
)
"""))
def test_java_depends_on_python(self):
self.assert_console_output_ordered(
'internal-src.java.java_depends_on_python.java_depends_on_python',
' internal-common.d.d',
targets=[self.target('src/java/java_depends_on_python')]
)
def test_empty(self):
self.assert_console_output_ordered(
'internal-common.a.a',
targets=[self.target('common/a')]
)
def test_jar_library(self):
self.assert_console_output_ordered(
'internal-common.b.b',
targets=[self.target('common/b')],
)
def test_java_library(self):
self.assert_console_output_ordered(
'internal-common.c.c',
targets=[self.target('common/c')]
)
def test_python_library(self):
self.assert_console_output_ordered(
'internal-common.d.d',
targets=[self.target('common/d')]
)
def test_python_binary(self):
self.assert_console_output_ordered(
'internal-common.e.e',
targets=[self.target('common/e')]
)
def test_jvm_binary1(self):
self.assert_console_output_ordered(
'internal-common.f.f',
targets=[self.target('common/f')]
)
def test_jvm_binary2(self):
self.assert_console_output_ordered(
'internal-common.g.g',
' internal-common.f.f',
targets=[self.target('common/g')]
)
def test_jvm_app1(self):
self.assert_console_output_ordered(
'internal-common.h.h',
' internal-common.f.f',
targets=[self.target('common/h')]
)
def test_jvm_app2(self):
self.assert_console_output_ordered(
'internal-common.i.i',
' internal-common.g.g',
' internal-common.f.f',
targets=[self.target('common/i')]
)
def test_overlaps_one(self):
self.assert_console_output_ordered(
'internal-overlaps.one',
' internal-common.h.h',
' internal-common.f.f',
' internal-common.i.i',
' internal-common.g.g',
' *internal-common.f.f',
targets=[self.target('overlaps:one')]
)
def test_overlaps_two(self):
self.assert_console_output_ordered(
'internal-overlaps.two',
' internal-overlaps.one',
' internal-common.h.h',
' internal-common.f.f',
' internal-common.i.i',
' internal-common.g.g',
' *internal-common.f.f',
targets=[self.target('overlaps:two')]
)
def test_overlaps_two_minimal(self):
self.assert_console_output_ordered(
'internal-overlaps.two',
' internal-overlaps.one',
' internal-common.h.h',
' internal-common.f.f',
' internal-common.i.i',
' internal-common.g.g',
targets=[self.target('overlaps:two')],
options={'minimal': True}
)
def test_multi(self):
self.assert_console_output_ordered(
'internal-common.g.g',
' internal-common.f.f',
'internal-common.h.h',
' internal-common.f.f',
'internal-common.i.i',
' internal-common.g.g',
' internal-common.f.f',
targets=[self.target('common/g'), self.target('common/h'), self.target('common/i')]
)
def test_path_to(self):
self.assert_console_output_ordered(
'internal-overlaps.two',
' internal-overlaps.one',
' internal-common.i.i',
' internal-common.g.g',
targets=[self.target('overlaps:two')],
options={'path_to': 'internal-common.g.g'},
)
def test_resources(self):
self.assert_console_output_ordered(
'internal-src.java.a.a_java',
' internal-resources.a.a_resources',
targets=[self.target('src/java/a:a_java')]
)
def test_resources_dep(self):
self.assert_console_output_ordered(
'internal-src.java.a.a_dep',
' internal-src.java.a.a_java',
' internal-resources.a.a_resources',
targets=[self.target('src/java/a:a_dep')]
)
def test_intermediate_dep(self):
self.assert_console_output_ordered(
'internal-src.java.b.b_java',
' internal-src.java.b.b_dep',
' internal-src.java.b.b_lib',
targets=[self.target('src/java/b:b_java')]
)
class ProjectInfoTest(ConsoleTaskTestBase):
@classmethod
def task_type(cls):
return Depmap
@property
def alias_groups(self):
return register_core().merge(register_jvm())
def setUp(self):
super(ProjectInfoTest, self).setUp()
self.make_target(
'project_info:first',
target_type=JarLibrary,
)
jar_lib = self.make_target(
'project_info:jar_lib',
target_type=JarLibrary,
jars=[JarDependency('org.apache', 'apache-jar', '12.12.2012')],
)
self.make_target(
'java/project_info:java_lib',
target_type=JavaLibrary,
sources=['com/foo/Bar.java', 'com/foo/Baz.java'],
)
self.make_target(
'project_info:third',
target_type=ScalaLibrary,
dependencies=[jar_lib],
java_sources=['java/project_info:java_lib'],
sources=['com/foo/Bar.scala', 'com/foo/Baz.scala'],
)
self.make_target(
'project_info:jvm_app',
target_type=JvmApp,
dependencies=[jar_lib],
)
self.make_target(
'project_info:jvm_target',
target_type=ScalaLibrary,
dependencies=[jar_lib],
sources=['this/is/a/source/Foo.scala', 'this/is/a/source/Bar.scala'],
)
test_resource = self.make_target(
'project_info:test_resource',
target_type=Resources,
sources=['y_resource', 'z_resource'],
)
self.make_target(
'project_info:java_test',
target_type=JavaTests,
dependencies=[jar_lib],
sources=['this/is/a/test/source/FooTest.scala'],
resources=[test_resource],
)
jvm_binary = self.make_target(
'project_info:jvm_binary',
target_type=JvmBinary,
dependencies=[jar_lib],
)
self.make_target(
'project_info:top_dependency',
target_type=Dependencies,
dependencies=[jvm_binary],
)
src_resource = self.make_target(
'project_info:resource',
target_type=Resources,
sources=['a_resource', 'b_resource'],
)
self.make_target(
'project_info:target_type',
target_type=ScalaLibrary,
dependencies=[jvm_binary],
resources=[src_resource],
)
self.make_target(
'project_info:unrecognized_target_type',
target_type=JvmTarget,
dependencies=[],
resources=[],
)
# TODO: All these tests require the deprecated project_info option to be True.
# They will need to be rewritten in order to remove that option.
def get_depmap_task_result(self, targets, extra_options=None):
options = { 'project_info': True }
if extra_options:
options.update(extra_options)
return self.execute_console_task(targets=targets, options=options)
def get_depmap_task_json(self, targets):
self.set_options(project_info=True)
return json.loads(''.join(self.get_depmap_task_result(targets=targets)))
def test_without_dependencies(self):
# Are these tests failing? --project-info is to be removed
# from the depmap target in 0.0.31. The ProjectInfoTest suite
# has already been moved to test_export.py so you can remove
# this class from test_depmap.py when it goes away.
result = self.get_depmap_task_json(targets=[self.target('project_info:first')])
self.assertEqual({}, result['libraries'])
def test_with_dependencies(self):
result = self.get_depmap_task_json(targets=[self.target('project_info:third')])
self.assertEqual(
[
'java/project_info:java_lib',
'project_info:jar_lib'
],
sorted(result['targets']['project_info:third']['targets'])
)
self.assertEqual(['org.apache:apache-jar:12.12.2012'],
result['targets']['project_info:third']['libraries'])
self.assertEqual(1, len(result['targets']['project_info:third']['roots']))
source_root = result['targets']['project_info:third']['roots'][0]
self.assertEqual('com.foo', source_root['package_prefix'])
self.assertEqual(
'{0}/project_info/com/foo'.format(self.build_root),
source_root['source_root']
)
def test_jvm_app(self):
result = self.get_depmap_task_json(targets=[self.target('project_info:jvm_app')])
self.assertEqual(['org.apache:apache-jar:12.12.2012'],
result['targets']['project_info:jvm_app']['libraries'])
def test_jvm_target(self):
result = self.get_depmap_task_json(targets=[self.target('project_info:jvm_target')])
jvm_target = result['targets']['project_info:jvm_target']
expected_jmv_target = {
'libraries': ['org.apache:apache-jar:12.12.2012'],
'is_code_gen': False,
'targets': ['project_info:jar_lib'],
'roots': [
{
'source_root': '{root}/project_info/this/is/a/source'.format(root=self.build_root),
'package_prefix': 'this.is.a.source'
},
],
'target_type': 'SOURCE',
'pants_target_type': 'scala_library'
}
self.assertEqual(jvm_target, expected_jmv_target)
def test_java_test(self):
result = self.get_depmap_task_json(targets=[self.target('project_info:java_test')])
self.assertEqual('TEST', result['targets']['project_info:java_test']['target_type'])
self.assertEqual(['org.apache:apache-jar:12.12.2012'],
result['targets']['project_info:java_test']['libraries'])
self.assertEqual('TEST_RESOURCE',
result['targets']['project_info:test_resource']['target_type'])
def test_jvm_binary(self):
result = self.get_depmap_task_json(targets=[self.target('project_info:jvm_binary')])
self.assertEqual(['org.apache:apache-jar:12.12.2012'],
result['targets']['project_info:jvm_binary']['libraries'])
def test_top_dependency(self):
result = self.get_depmap_task_json(targets=[self.target('project_info:top_dependency')])
self.assertEqual([], result['targets']['project_info:top_dependency']['libraries'])
self.assertEqual(['project_info:jvm_binary'],
result['targets']['project_info:top_dependency']['targets'])
def test_format_flag(self):
result = self.get_depmap_task_result(targets=[self.target('project_info:third')],
extra_options={'project_info_formatted': False})
# confirms only one line of output, which is what -format should produce
self.assertEqual(1, len(result))
def test_target_types(self):
result = self.get_depmap_task_json(targets=[self.target('project_info:target_type')])
self.assertEqual('SOURCE',
result['targets']['project_info:target_type']['target_type'])
self.assertEqual('RESOURCE', result['targets']['project_info:resource']['target_type'])
def test_output_file(self):
outfile = os.path.join(self.build_root, '.pants.d', 'test')
self.get_depmap_task_result(targets=[self.target('project_info:target_type')],
extra_options={'output_file': outfile})
self.assertTrue(os.path.exists(outfile))
def test_output_file_error(self):
with self.assertRaises(TaskError):
self.get_depmap_task_result(targets=[self.target('project_info:target_type')],
extra_options={'output_file': self.build_root})
def test_unrecognized_target_type(self):
with self.assertRaises(TaskError):
self.get_depmap_task_result(targets=[self.target('project_info:unrecognized_target_type')])
|
<reponame>philip-dds/atst
import datetime
from sqlalchemy.orm.exc import NoResultFound
from atst.database import db
from atst.models import ApplicationInvitation, InvitationStatus, PortfolioInvitation
from atst.domain.portfolio_roles import PortfolioRoles
from atst.domain.application_roles import ApplicationRoles
from .exceptions import NotFoundError
class WrongUserError(Exception):
def __init__(self, user, invite):
self.user = user
self.invite = invite
@property
def message(self):
return "User {} with DOD ID {} does not match expected DOD ID {} for invitation {}".format(
self.user.id, self.user.dod_id, self.invite.user.dod_id, self.invite.id
)
class ExpiredError(Exception):
def __init__(self, invite):
self.invite = invite
@property
def message(self):
return "Invitation {} has expired.".format(self.invite.id)
class InvitationError(Exception):
def __init__(self, invite):
self.invite = invite
@property
def message(self):
return "{} has a status of {}".format(self.invite.id, self.invite.status.value)
class BaseInvitations(object):
model = None
role_domain_class = None
# number of minutes a given invitation is considered valid
EXPIRATION_LIMIT_MINUTES = 360
@classmethod
def _get(cls, token):
try:
invite = db.session.query(cls.model).filter_by(token=token).one()
except NoResultFound:
raise NotFoundError(cls.model.__tablename__)
return invite
@classmethod
def create(cls, inviter, role, member_data, commit=False):
# pylint: disable=not-callable
invite = cls.model(
role=role,
inviter=inviter,
user=role.user,
status=InvitationStatus.PENDING,
expiration_time=cls.current_expiration_time(),
email=member_data.get("email"),
dod_id=member_data.get("dod_id"),
first_name=member_data.get("first_name"),
phone_number=member_data.get("phone_number"),
last_name=member_data.get("last_name"),
)
db.session.add(invite)
if commit:
db.session.commit()
return invite
@classmethod
def accept(cls, user, token):
invite = cls._get(token)
if invite.dod_id != user.dod_id:
if invite.is_pending:
cls._update_status(invite, InvitationStatus.REJECTED_WRONG_USER)
raise WrongUserError(user, invite)
elif invite.is_expired:
cls._update_status(invite, InvitationStatus.REJECTED_EXPIRED)
raise ExpiredError(invite)
elif invite.is_accepted or invite.is_revoked or invite.is_rejected:
raise InvitationError(invite)
elif invite.is_pending: # pragma: no branch
cls._update_status(invite, InvitationStatus.ACCEPTED)
cls.role_domain_class.enable(invite.role, user)
return invite
@classmethod
def current_expiration_time(cls):
return datetime.datetime.now() + datetime.timedelta(
minutes=cls.EXPIRATION_LIMIT_MINUTES
)
@classmethod
def _update_status(cls, invite, new_status):
invite.status = new_status
db.session.add(invite)
db.session.commit()
return invite
@classmethod
def revoke(cls, token):
invite = cls._get(token)
invite = cls._update_status(invite, InvitationStatus.REVOKED)
cls.role_domain_class.disable(invite.role)
return invite
@classmethod
def resend(cls, inviter, token, user_info=None):
previous_invitation = cls._get(token)
cls._update_status(previous_invitation, InvitationStatus.REVOKED)
if not user_info:
user_info = {
"email": previous_invitation.email,
"dod_id": previous_invitation.dod_id,
"first_name": previous_invitation.first_name,
"last_name": previous_invitation.last_name,
"phone_number": previous_invitation.phone_number,
"phone_ext": previous_invitation.phone_ext,
}
return cls.create(inviter, previous_invitation.role, user_info, commit=True)
class PortfolioInvitations(BaseInvitations):
model = PortfolioInvitation
role_domain_class = PortfolioRoles
class ApplicationInvitations(BaseInvitations):
model = ApplicationInvitation
role_domain_class = ApplicationRoles
|
<filename>pylbm/generator/ast.py<gh_stars>0
# FIXME: make pylint happy !
#pylint: disable=all
from sympy.core import Symbol, Expr, Tuple
from sympy.core.sympify import _sympify, sympify
from sympy.tensor import Idx, IndexedBase, Indexed
from sympy.core.basic import Basic
from sympy.core.relational import Relational
from sympy.core.compatibility import is_sequence, string_types
from sympy.core.sympify import _sympify
from sympy.functions.special.tensor_functions import KroneckerDelta
from sympy.core import Expr, Tuple, Symbol, sympify, S
from sympy.core.compatibility import is_sequence, string_types, NotIterable, range
class Assignment(Relational):
"""
Represents variable assignment for code generation.
Parameters
----------
lhs : Expr
Sympy object representing the lhs of the expression. These should be
singular objects, such as one would use in writing code. Notable types
include Symbol, MatrixSymbol, MatrixElement, and Indexed. Types that
subclass these types are also supported.
rhs : Expr
Sympy object representing the rhs of the expression. This can be any
type, provided its shape corresponds to that of the lhs. For example,
a Matrix type can be assigned to MatrixSymbol, but not to Symbol, as
the dimensions will not align.
Examples
========
>>> from sympy import symbols, MatrixSymbol, Matrix
>>> from sympy.printing.codeprinter import Assignment
>>> x, y, z = symbols('x, y, z')
>>> Assignment(x, y)
Assignment(x, y)
>>> Assignment(x, 0)
Assignment(x, 0)
>>> A = MatrixSymbol('A', 1, 3)
>>> mat = Matrix([x, y, z]).T
>>> Assignment(A, mat)
Assignment(A, Matrix([[x, y, z]]))
>>> Assignment(A[0, 1], x)
Assignment(A[0, 1], x)
"""
rel_op = ':='
__slots__ = []
def __new__(cls, lhs, rhs=0, **assumptions):
from sympy.matrices.expressions.matexpr import (
MatrixElement, MatrixSymbol)
from sympy.tensor.indexed import Indexed
lhs = _sympify(lhs)
rhs = _sympify(rhs)
# Tuple of things that can be on the lhs of an assignment
assignable = (Symbol, MatrixSymbol, MatrixElement, Indexed)
#if not isinstance(lhs, assignable):
# raise TypeError("Cannot assign to lhs of type %s." % type(lhs))
# Indexed types implement shape, but don't define it until later. This
# causes issues in assignment validation. For now, matrices are defined
# as anything with a shape that is not an Indexed
lhs_is_mat = hasattr(lhs, 'shape') and not isinstance(lhs, Indexed)
rhs_is_mat = hasattr(rhs, 'shape') and not isinstance(rhs, Indexed)
# If lhs and rhs have same structure, then this assignment is ok
if lhs_is_mat:
if not rhs_is_mat:
raise ValueError("Cannot assign a scalar to a matrix.")
elif lhs.shape != rhs.shape:
raise ValueError("Dimensions of lhs and rhs don't align.")
elif rhs_is_mat and not lhs_is_mat:
raise ValueError("Cannot assign a matrix to a scalar.")
return Relational.__new__(cls, lhs, rhs, **assumptions)
class AssignmentIf(Assignment):
rel_op = '=='
__slots__ = []
class For(Basic):
def __new__(cls, idx, expr, **kw_args):
if isinstance(idx, Idx):
index = Tuple(idx)
elif is_sequence(idx):
index = Tuple(*idx)
else:
raise TypeError("Loop object requires an Idx or a list of Idx.")
if is_sequence(expr):
expr = Tuple(*expr)
else:
expr = Tuple(expr)
args = index, expr
obj = Basic.__new__(cls, *args, **kw_args)
return obj
@property
def index(self):
return self.args[0]
@property
def expr(self):
return self.args[1]
def _sympystr(self, p):
return p.doprint(p)
class If(Basic):
def __new__(cls, *args, **options):
newargs = []
for ec in args:
cond = ec[0]
expr = ec[1]
if is_sequence(expr):
expr = Tuple(*expr)
else:
expr = Tuple(expr)
newargs.append(Tuple(cond, expr))
obj = Basic.__new__(cls, *newargs, **options)
return obj
@property
def statement(self):
return self.args
class IdxRange(Basic):
def __new__(cls, *args):
if len(args) > 4:
raise ValueError("Range is defined by (top), (start, stop) or (start, stop, step)")
# for a in args:
# print(type(a))
# if not isinstance(a, (int, Symbol, Add)):
# raise TypeError("args in Range must be integer or SymPy Idx")
# expand range
label = args[0]
slc = slice(*args[1:])
if slc.step == 0:
raise ValueError("step cannot be 0")
start, stop, step = slc.start or 0, slc.stop, slc.step or 1
start = sympify(start)
stop = sympify(stop)
step = sympify(step)
return Basic.__new__(cls, label, start, stop, step)
@property
def label(self):
return self.args[0]
@property
def start(self):
return self.args[1]
@property
def stop(self):
return self.args[2]
@property
def step(self):
return self.args[3]
class IndexedIntBase(IndexedBase):
is_integer = True
is_Integer = True
|
<reponame>cedriczirtacic/avr_instruction_set<gh_stars>0
#!/usr/bin/env python
import requests
import sys
import re
from bs4 import BeautifulSoup as BS
from jinja2 import Template, Environment, PackageLoader
index_url = 'https://www.microchip.com/webdoc/avrassembler/' + \
'avrassembler.wb_instruction_list.html'
inst_url = 'https://www.microchip.com/webdoc/avrassembler/%s'
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6)' + \
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
class Parser():
__bs = None
__html = ''
def __init__(self):
return None
def load(self, html):
self.__bs = BS(html, 'html.parser')
def clear(self):
self.__bs = None
def get_html(self, tag, _id=None, _class=None):
tags = self.__bs.find_all(tag, id=_id)
if len(tags) == 0:
return None
if _class != None:
for tag in tags:
if _class == tag.get('class'):
return [tag]
return tags
def perror(e):
sys.stderr.write("%s\n" % e)
def GET(url):
headers = { 'User-Agent': user_agent }
r = requests.get(url, headers=headers)
if r.status_code != 200:
perror("GET(): error getting content (code: %d)"
% r.status_code)
return None
return r
def main(args):
# steal data
index = GET(index_url)
if index == None:
return False
# setup parser and template environment
tpl_env = Environment(loader=PackageLoader('__main__',
'templates'))
p = Parser()
p.load(index.text)
# get table of contents
content = p.get_html('div',_class='chapter')
if content == None:
perror("Parser.get_html(): error parsing tags")
return False
# get links and beautify them
rawlinks = content[0].find_all('a')
instructs = {}
ids = 0
for l in rawlinks:
t = l.get_text()
if t == '':
continue
t = re.sub(r'[\r\n]+', '', t)
m = re.match(r'^\s*(?P<inst>[A-Z\s\(\)]+?)\s*-\s*(?P<desc>.+)$', t, \
re.MULTILINE)
if m == None:
continue
instructs[m.group('inst')] = \
{'id': ids, 'desc':m.group('desc'), 'href': l.get('href') }
ids += 1
template = tpl_env.get_template('index.tpl')
render = template.render(inst=instructs)
# generate index
fd = open('./index.html','w')
fd.write(render)
fd.close()
p.clear()
template = tpl_env.get_template('instruction.tpl')
for i in instructs:
inst_data = GET(inst_url % instructs[i]['href'])
if inst_data == None:
perror("main(): error. Not generating %s!" % i)
continue
p.load(inst_data.text)
content = p.get_html('div', _class='section')
if content == None:
perror("Parser.get_html(): error parsing tags")
continue
render = template.render(instruction=i,content=content[0])
fd = open(instructs[i]['href'],'wb')
fd.write(render.encode('utf-8'))
fd.close()
p.clear()
return True
if __name__ == '__main__':
quit(main(sys.argv))
|
import HTMLParser
import base64
from contextlib import contextmanager
from functools import wraps
import hashlib
import hmac
import ujson
import re
import urllib
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.http.response import HttpResponse
from django.shortcuts import redirect
from django.utils import timezone
from WhatManager2.settings import SECRET_KEY
WHAT_DOWNLOAD_LINK_RE = re.compile(re.escape('torrents.php?action=download&id=') + '(\d+)')
@contextmanager
def dummy_context_manager(*args, **kwargs):
yield
def json_return_method(fn):
@wraps(fn)
def wrapped(*args, **kwargs):
val = fn(*args, **kwargs)
if type(val) is HttpResponse:
return val
return HttpResponse(ujson.dumps(val), content_type='text/json')
return wrapped
def html_unescape(data):
html_parser = HTMLParser.HTMLParser()
return html_parser.unescape(data)
def norm_hash(hash):
return hash.upper()
def norm_t_torrent(t):
t.hashString = norm_hash(t.hashString)
if 'addedDate' in t._fields:
t.date_added_tz = timezone.make_aware(t.date_added, timezone.get_default_timezone())
def match_properties(a, b, props):
for prop in props:
if getattr(a, prop[0]) != getattr(b, prop[1]):
return False
return True
def copy_properties(a, b, props):
for prop in props:
setattr(a, prop[0], getattr(b, prop[1]))
def wm_hmac(plaintext):
bin_sig = hmac.new(SECRET_KEY, plaintext, hashlib.sha256).digest()
return base64.urlsafe_b64encode(bin_sig)
def build_url(*args, **kwargs):
get = kwargs.pop('get', {})
url = reverse(*args, **kwargs)
if get:
url += '?' + urllib.urlencode(get)
return url
def get_user_token(user):
return wm_hmac(user.username)
def auth_username_token(fn):
def inner(request, *args, **kwargs):
if not request.user.is_authenticated():
try:
user = User.objects.get(username=request.GET.get('username'))
except User.DoesNotExist:
return redirect('login.views.login')
if get_user_token(user) != request.GET['token']:
return redirect('login.views.login')
request.user = user
return fn(request, *args, **kwargs)
return inner
def wm_unicode(s):
if isinstance(s, str):
return s.decode('utf-8')
elif isinstance(s, unicode):
return s
raise Exception('Unknown string type: {0}'.format(type(s)))
def wm_str(s):
if isinstance(s, unicode):
return s.encode('utf-8')
elif isinstance(s, str):
return s
raise Exception('Unknown string type: {0}'.format(type(s)))
class JoinedArtistsBuilder(object):
def __init__(self, joined_artists_builder=None):
if joined_artists_builder is None:
self.result = []
else:
self.result = list(joined_artists_builder.result)
def append_joined(self, join_string, artists):
for a in artists:
self.result.append({
u'id': a['id'],
u'name': a['name'],
u'join': join_string,
})
self.result[-1]['join'] = ''
def append_artist(self, artist):
self.result.append({
u'id': artist['id'],
u'name': html_unescape(artist['name']),
u'join': '',
})
def append_join(self, join_string):
assert not self.result[-1][u'join'], 'Last join should be empty before adding a new join'
self.result[-1][u'join'] = join_string
def clear(self):
self.result = []
def get_artists_list(group):
a_main = group['musicInfo']['artists']
a_composers = group['musicInfo']['composers']
a_conductors = group['musicInfo']['conductor']
a_djs = group['musicInfo']['dj']
if len(a_main) == 0 and len(a_conductors) == 0 and len(a_djs) == 0 and len(a_composers) == 0:
return []
builder = JoinedArtistsBuilder()
if len(a_composers) and len(a_composers) < 3:
builder.append_joined(u' & ', a_composers)
if len(a_composers) < 3 and len(a_main) > 0:
builder.append_join(u' performed by ')
composer_builder = JoinedArtistsBuilder(builder)
if len(a_main):
if len(a_main) <= 2:
builder.append_joined(u' & ', a_main)
else:
builder.append_artist({u'id': -1, u'name': u'Various Artists'})
if len(a_conductors):
if (len(a_main) or len(a_composers)) and (len(a_composers) < 3 or len(a_main)):
builder.append_join(u' under ')
if len(a_conductors) <= 2:
builder.append_joined(u' & ', a_conductors)
else:
builder.append_artist({u'id': -1, u'name': u'Various Conductors'})
if len(a_composers) and len(a_main) + len(a_conductors) > 3 and len(a_main) > 1 and len(
a_conductors) > 1:
builder = composer_builder
builder.append_artist({u'id': -1, u'name': u'Various Artists'})
elif len(a_composers) > 2 and len(a_main) + len(a_conductors) == 0:
builder.clear()
builder.append_artist({u'id': -1, u'name': u'Various Composers'})
if len(a_djs):
if len(a_djs) <= 2:
builder.clear()
builder.append_joined(u' & ', a_djs)
else:
builder.clear()
builder.append_artist({u'id': -1, u'name': u'Various DJs'})
return builder.result
def get_artists(group):
artists_list = get_artists_list(group)
result = []
for a in artists_list:
result.append(a['name'])
result.append(a['join'])
return u''.join(result)
def read_text(path):
with open(path, 'rb') as f:
return f.read()
def write_text(path, text):
with open(path, 'wb') as f:
f.write(text)
|
import collections
import gc
import os
from typing import List, Optional, Union, Tuple, Dict, Any
import albumentations
import numpy as np
import pandas as pd
import torch
from hydra.utils import instantiate
from pytorch_toolbelt.inference import (
ApplySigmoidTo,
ApplySoftmaxTo,
Ensembler,
GeneralizedTTA,
MultiscaleTTA,
d2_image_augment,
d4_image_augment,
d4_image_deaugment,
d2_image_deaugment,
flips_image_deaugment,
flips_image_augment,
fliplr_image_augment,
fliplr_image_deaugment,
)
from pytorch_toolbelt.utils import to_numpy, fs
from torch import nn
from torch.utils.data import DistributedSampler
from tqdm import tqdm
from pytorch_toolbelt.utils.distributed import is_main_process, get_rank, get_world_size, all_gather
from xview3.centernet.bboxer import (
MultilabelCircleNetDecodeResult,
MultilabelCircleNetCoder,
)
from xview3.centernet.constants import (
CENTERNET_OUTPUT_SIZE,
CENTERNET_OUTPUT_OFFSET,
CENTERNET_OUTPUT_OBJECTNESS_MAP,
CENTERNET_OUTPUT_VESSEL_MAP,
CENTERNET_OUTPUT_FISHING_MAP,
)
from xview3.centernet.models.inference import (
multilabel_centernet_tiled_inference,
get_box_coder_from_model,
)
from xview3.dataset import (
XView3DataModule,
read_multichannel_image,
stack_multichannel_image,
)
__all__ = [
"average_checkpoints",
"ensemble_from_checkpoints",
"model_from_checkpoint",
"ensemble_from_config",
"wrap_multilabel_model_with_tta",
"maybe_run_inference",
]
def average_checkpoints(inputs):
"""Loads checkpoints from inputs and returns a model with averaged weights. Original implementation taken from:
https://github.com/pytorch/fairseq/blob/a48f235636557b8d3bc4922a6fa90f3a0fa57955/scripts/average_checkpoints.py#L16
Args:
inputs (List[str]): An iterable of string paths of checkpoints to load from.
Returns:
A dict of string keys mapping to various values. The 'model' key
from the returned dict should correspond to an OrderedDict mapping
string parameter names to torch Tensors.
"""
params_dict = collections.OrderedDict()
params_keys = None
new_state = None
num_models = len(inputs)
for fpath in inputs:
with open(fpath, "rb") as f:
state = torch.load(
f,
map_location="cpu",
)
# Copies over the settings from the first checkpoint
if new_state is None:
new_state = state
model_params = state["model_state_dict"]
model_params_keys = list(model_params.keys())
if params_keys is None:
params_keys = model_params_keys
elif params_keys != model_params_keys:
raise KeyError("For checkpoint {}, expected list of params: {}, " "but found: {}".format(f, params_keys, model_params_keys))
for k in params_keys:
p = model_params[k]
if isinstance(p, torch.HalfTensor):
p = p.float()
if k not in params_dict:
params_dict[k] = p.clone()
# NOTE: clone() is needed in case of p is a shared parameter
else:
params_dict[k] += p
averaged_params = collections.OrderedDict()
for k, v in params_dict.items():
averaged_params[k] = v
if averaged_params[k].is_floating_point():
averaged_params[k].div_(num_models)
else:
averaged_params[k] //= num_models
new_state["model_state_dict"] = averaged_params
return new_state
def model_from_checkpoint(checkpoint_config: Union[str, Dict], **kwargs) -> Tuple[nn.Module, Dict]:
if isinstance(checkpoint_config, collections.Mapping):
if "average_checkpoints" in checkpoint_config:
checkpoint = average_checkpoints(checkpoint_config["average_checkpoints"])
else:
checkpoint_name = checkpoint_config["checkpoint"]
if os.path.isfile(checkpoint_name):
checkpoint = torch.load(checkpoint_name, map_location="cpu")
else:
checkpoint = torch.hub.load_state_dict_from_url(checkpoint_name)
model_config = checkpoint["checkpoint_data"]["config"]["model"]
else:
checkpoint_name = checkpoint_config
if os.path.isfile(checkpoint_name):
checkpoint = torch.load(checkpoint_name, map_location="cpu")
else:
checkpoint = torch.hub.load_state_dict_from_url(checkpoint_name)
model_config = checkpoint["checkpoint_data"]["config"]["model"]
model_state_dict = checkpoint["model_state_dict"]
model = instantiate(model_config, _recursive_=False)
model.load_state_dict(model_state_dict, strict=False)
return model.eval(), checkpoint
def wrap_multilabel_model_with_tta(model, tta_mode, with_offset=True, size_offsets=(0, -32, -64, +32, +64)):
from xview3.centernet import (
CENTERNET_OUTPUT_VESSEL_MAP,
CENTERNET_OUTPUT_FISHING_MAP,
CENTERNET_OUTPUT_OBJECTNESS_MAP,
CENTERNET_OUTPUT_OFFSET,
CENTERNET_OUTPUT_SIZE,
)
keys_to_deaug = [
CENTERNET_OUTPUT_VESSEL_MAP,
CENTERNET_OUTPUT_FISHING_MAP,
CENTERNET_OUTPUT_OBJECTNESS_MAP,
CENTERNET_OUTPUT_SIZE,
]
if with_offset:
keys_to_deaug.append(CENTERNET_OUTPUT_OFFSET)
def _make_deaug_dict(keys, fn):
return dict((key, fn) for key in keys)
if tta_mode == "d4":
return GeneralizedTTA(model, augment_fn=d4_image_augment, deaugment_fn=_make_deaug_dict(keys_to_deaug, d4_image_deaugment))
elif tta_mode == "ms":
return MultiscaleTTA(model, size_offsets)
elif tta_mode == "d2-ms":
return MultiscaleTTA(GeneralizedTTA(model, d2_image_augment, d2_image_deaugment), size_offsets)
elif tta_mode == "d2":
model = GeneralizedTTA(model, d2_image_augment, deaugment_fn=_make_deaug_dict(keys_to_deaug, d2_image_deaugment))
elif tta_mode == "flips":
model = GeneralizedTTA(model, flips_image_augment, deaugment_fn=_make_deaug_dict(keys_to_deaug, flips_image_deaugment))
elif tta_mode == "fliplr":
model = GeneralizedTTA(model, fliplr_image_augment, deaugment_fn=_make_deaug_dict(keys_to_deaug, fliplr_image_deaugment))
elif tta_mode is None:
return model
else:
raise KeyError("Unusupported TTA mode '" + tta_mode + "'")
return model
def ensemble_from_checkpoints(
checkpoint_fnames: List[str],
strict=True,
sigmoid_outputs=None,
softmax_outputs=None,
activation: str = "after_model",
tta: Optional[str] = None,
with_offset=True,
):
if activation not in {None, "None", "after_model", "after_tta", "after_ensemble"}:
raise KeyError(activation)
models = []
checkpoints = []
for ck in checkpoint_fnames:
model, checkpoint = model_from_checkpoint(ck, strict=strict)
models.append(model)
checkpoints.append(checkpoint)
if activation == "after_model":
if sigmoid_outputs is not None:
models = [ApplySigmoidTo(m, output_key=sigmoid_outputs) for m in models]
print("Applying sigmoid activation to", sigmoid_outputs, "after each model", len(models))
if softmax_outputs is not None:
models = [ApplySoftmaxTo(m, output_key=softmax_outputs) for m in models]
print("Applying softmax activation to", softmax_outputs, "after each model", len(models))
if len(models) > 1:
model = Ensembler(models)
if activation == "after_ensemble":
if sigmoid_outputs is not None:
model = ApplySigmoidTo(model, output_key=sigmoid_outputs)
print("Applying sigmoid activation to", sigmoid_outputs, "after ensemble")
if softmax_outputs is not None:
model = ApplySoftmaxTo(model, output_key=softmax_outputs)
print("Applying softmax activation to", softmax_outputs, "after ensemble")
else:
assert len(models) == 1
model = models[0]
if tta not in {None, "None"}:
model = wrap_multilabel_model_with_tta(model, tta, with_offset=with_offset)
print("Wrapping models with TTA", tta)
if activation == "after_tta":
if sigmoid_outputs is not None:
model = ApplySigmoidTo(model, output_key=sigmoid_outputs)
print("Applying sigmoid activation to ", sigmoid_outputs, " after TTA")
if softmax_outputs is not None:
model = ApplySoftmaxTo(model, output_key=softmax_outputs)
print("Applying softmax activation to", softmax_outputs, "after TTA")
return model.eval(), checkpoints
def ensemble_from_config(config: Dict[str, Any]):
model, checkpoints = ensemble_from_checkpoints(
checkpoint_fnames=config["ensemble"]["models"],
strict=True,
activation=config["ensemble"]["activation_after"],
tta=config["ensemble"]["tta"],
sigmoid_outputs=config["ensemble"]["sigmoid_outputs"],
softmax_outputs=config["ensemble"]["softmax_outputs"],
with_offset=config["ensemble"]["with_offset"],
)
box_coder = get_box_coder_from_model(model)
model = model.eval().cuda()
return model, checkpoints, box_coder
@torch.jit.optimized_execution(False)
def predict_multilabel_scenes(
model,
box_coder: MultilabelCircleNetCoder,
scenes: List[str],
channels: List[str],
tile_step: int,
tile_size: int,
objectness_thresholds_lower_bound: float,
normalization: Dict[str, albumentations.ImageOnlyTransform],
accumulate_on_gpu: bool,
fp16: bool,
batch_size: int,
apply_activation: bool,
save_raw_predictions: bool,
max_objects: int,
channels_last: bool,
output_predictions_dir=None,
) -> pd.DataFrame:
if output_predictions_dir is not None:
os.makedirs(output_predictions_dir, exist_ok=True)
all_predictions = []
scenes = np.array(scenes)
world_size, local_rank = get_world_size(), get_rank()
if world_size > 1:
sampler = DistributedSampler(scenes, world_size, local_rank, shuffle=False)
rank_local_indexes = np.array(list(iter(sampler)))
scenes = scenes[rank_local_indexes]
print("Node", local_rank, "got", len(scenes), "to process")
torch.distributed.barrier()
for scene in tqdm(scenes, desc=f"Inference at Node {local_rank}/{world_size}", position=local_rank):
gc.collect()
scene_id = fs.id_from_fname(scene)
predictions = maybe_run_inference(
model=model,
box_coder=box_coder,
scene=scene,
output_predictions_dir=output_predictions_dir,
accumulate_on_gpu=accumulate_on_gpu,
tile_size=tile_size,
tile_step=tile_step,
fp16=fp16,
batch_size=batch_size,
save_raw_predictions=save_raw_predictions,
apply_activation=apply_activation,
max_objects=max_objects,
channels_last=channels_last,
normalization=normalization,
channels=channels,
objectness_thresholds_lower_bound=objectness_thresholds_lower_bound,
)
all_predictions.append(predictions)
if output_predictions_dir is not None:
predictions.to_csv(os.path.join(output_predictions_dir, scene_id + ".csv"), index=False)
all_predictions = pd.concat(all_predictions).reset_index(drop=True)
if world_size > 1:
torch.distributed.barrier()
all_predictions = pd.concat(all_gather(all_predictions)).reset_index(drop=True)
return all_predictions
def maybe_run_inference(
model,
box_coder,
scene,
output_predictions_dir,
channels,
normalization,
objectness_thresholds_lower_bound: float,
tile_size,
tile_step,
accumulate_on_gpu,
fp16,
batch_size,
save_raw_predictions,
apply_activation,
max_objects,
channels_last,
):
scene_id = fs.id_from_fname(scene)
predictions_computed_offline = False
if output_predictions_dir is not None:
raw_predictions_file = os.path.join(output_predictions_dir, scene_id + ".npz")
decoded_predictions_file = os.path.join(output_predictions_dir, scene_id + ".csv")
if os.path.isfile(decoded_predictions_file):
try:
predictions = pd.read_csv(decoded_predictions_file)
return predictions
except Exception as e:
print(e)
predictions_computed_offline = False
elif os.path.isfile(raw_predictions_file):
try:
saved_predictions = np.load(raw_predictions_file, allow_pickle=True)
outputs = dict(
CENTERNET_OUTPUT_OBJECTNESS_MAP=torch.from_numpy(saved_predictions[CENTERNET_OUTPUT_OBJECTNESS_MAP]),
CENTERNET_OUTPUT_VESSEL_MAP=torch.from_numpy(saved_predictions[CENTERNET_OUTPUT_VESSEL_MAP]),
CENTERNET_OUTPUT_FISHING_MAP=torch.from_numpy(saved_predictions[CENTERNET_OUTPUT_FISHING_MAP]),
CENTERNET_OUTPUT_SIZE=torch.from_numpy(saved_predictions[CENTERNET_OUTPUT_SIZE]),
CENTERNET_OUTPUT_OFFSET=torch.from_numpy(saved_predictions[CENTERNET_OUTPUT_OFFSET])
if CENTERNET_OUTPUT_OFFSET in saved_predictions
else None,
)
predictions_computed_offline = True
except Exception as e:
print(e)
predictions_computed_offline = False
if not predictions_computed_offline:
image = read_multichannel_image(scene, channels)
for channel_name in set(channels):
image[channel_name] = normalization[channel_name](image=image[channel_name])["image"]
image = stack_multichannel_image(image, channels)
outputs = multilabel_centernet_tiled_inference(
model,
image,
box_coder=box_coder,
tile_size=tile_size,
tile_step=tile_step,
accumulate_on_gpu=accumulate_on_gpu,
fp16=fp16,
batch_size=batch_size,
channels_last=channels_last,
)
if save_raw_predictions and output_predictions_dir is not None:
raw_predictions_file = os.path.join(output_predictions_dir, scene_id + ".npz")
predictions_dict = dict(
CENTERNET_OUTPUT_OBJECTNESS_MAP=to_numpy(outputs[CENTERNET_OUTPUT_OBJECTNESS_MAP]),
CENTERNET_OUTPUT_VESSEL_MAP=to_numpy(outputs[CENTERNET_OUTPUT_VESSEL_MAP]),
CENTERNET_OUTPUT_FISHING_MAP=to_numpy(outputs[CENTERNET_OUTPUT_FISHING_MAP]),
CENTERNET_OUTPUT_SIZE=to_numpy(outputs[CENTERNET_OUTPUT_SIZE]),
)
if CENTERNET_OUTPUT_OFFSET in outputs:
predictions_dict[CENTERNET_OUTPUT_OFFSET] = to_numpy(outputs[CENTERNET_OUTPUT_OFFSET])
np.savez(raw_predictions_file, **predictions_dict)
preds: MultilabelCircleNetDecodeResult = box_coder.decode(
objectness_map=outputs[CENTERNET_OUTPUT_OBJECTNESS_MAP],
is_vessel_map=outputs[CENTERNET_OUTPUT_VESSEL_MAP],
is_fishing_map=outputs[CENTERNET_OUTPUT_FISHING_MAP],
length_map=outputs[CENTERNET_OUTPUT_SIZE],
offset_map=outputs.get(CENTERNET_OUTPUT_OFFSET, None),
apply_activation=apply_activation,
max_objects=max_objects,
)
pos_mask = preds.scores[0] >= objectness_thresholds_lower_bound
centers = to_numpy(preds.centers[0][pos_mask]).astype(int)
scores = to_numpy(preds.scores[0, pos_mask]).astype(np.float32)
lengths = XView3DataModule.decode_lengths(preds.lengths[0, pos_mask])
is_vessel_prob = to_numpy(preds.is_vessel[0, pos_mask]).astype(np.float32)
is_fishing_prob = to_numpy(preds.is_fishing[0, pos_mask]).astype(np.float32)
predictions = collections.defaultdict(list)
for (
(detect_scene_column, detect_scene_row),
objectness_score,
is_vessel_p,
is_fishing_p,
vessel_length_m,
) in zip(centers, scores, is_vessel_prob, is_fishing_prob, lengths):
predictions["vessel_length_m"].append(vessel_length_m)
predictions["detect_scene_row"].append(detect_scene_row)
predictions["detect_scene_column"].append(detect_scene_column)
predictions["scene_id"].append(scene_id)
# Scores
predictions["objectness_p"].append(objectness_score)
predictions["is_vessel_p"].append(is_vessel_p)
predictions["is_fishing_p"].append(is_fishing_p)
# Thresholds
predictions["objectness_threshold"].append(objectness_thresholds_lower_bound)
predictions = pd.DataFrame.from_dict(predictions)
return predictions
|
from collections import defaultdict
from .utils import fix_dataclass_init_docs
from .sim import SimGrid
from .typing import Optional, Callable, Union, List, Tuple, Dict
import jax
import jax.numpy as jnp
from jax.config import config
from jax.experimental.optimizers import adam
import numpy as np
import dataclasses
import xarray
try:
HOLOVIEWS_IMPORTED = True
import holoviews as hv
from holoviews.streams import Pipe
import panel as pn
except ImportError:
HOLOVIEWS_IMPORTED = False
from .viz import scalar_metrics_viz
config.parse_flags_with_absl()
@fix_dataclass_init_docs
@dataclasses.dataclass
class OptProblem:
"""An optimization problem
An optimization problem consists of a neural network defined at least by input parameters :code:`rho`,
the transform function :code:`T(rho)` (:math:`T(\\rho(x, y))`) (default identity),
and objective function :code:`C(T(rho))` (:math:`C(T(\\rho(x, y)))`), which maps to a scalar.
For use with an inverse design problem (the primary use case in this module), the user can include an
FDFD simulation and a source (to be fed into the FDFD solver). The FDFD simulation and source are then
used to define a function :code:`S(eps) == S(T(rho))` that solves the FDFD problem
where `eps == T(rho)` (:math:`\\epsilon(x, y)) := T(\\rho(x, y))`),
in which case the objective function evaluates :code:`C(S(T(rho)))`
(:math:`\\epsilon(x, y)) := C(S(T((\\rho(x, y))))`).
Args:
transform_fn: The JAX-transformable transform function to yield epsilon (identity if None,
must be a single :code:`transform_fn` (to be broadcast to all)
or a list to match the FDFD objects respectively). Examples of transform_fn
could be smoothing functions, symmetry functions, and more (which can be compounded appropriately).
cost_fn: The JAX-transformable cost function (or tuple of such functions)
corresponding to src that takes in output of solve_fn from :code:`opt_solver`.
sim: SimGrid(s) used to generate the solver (FDFD is not run is :code:`fdfd` is :code:`None`)
source: A numpy array source (FDFD is not run is :code:`source` is :code:`None`)
metrics_fn: A metric_fn that returns useful dictionary data based on fields and FDFD object
at certain time intervals (specified in opt). Each problem is supplied this metric_fn
(Optional, ignored if :code:`None`).
"""
transform_fn: Callable
cost_fn: Callable
sim: SimGrid
source: str
metrics_fn: Optional[Callable[[np.ndarray, SimGrid], Dict]] = None
def __post_init__(self):
self.fn = self.sim.get_sim_sparams_fn(self.source, self.transform_fn)\
if self.source is not None else self.transform_fn
@fix_dataclass_init_docs
@dataclasses.dataclass
class OptViz:
"""An optimization visualization object
An optimization visualization object consists of a plot for monitoring the
history and current state of an optimization in real time.
Args:
cost_dmap: Cost dynamic map for streaming cost fn over time
simulations_panel: Simulations panel for visualizing simulation results from last iteration
costs_pipe: Costs pipe for streaming cost fn over time
simulations_pipes: Simulations pipes of form :code:`eps, field, power`
for visualizing simulation results from last iteration
metrics_panels: Metrics panels for streaming metrics over time for each simulation (e.g. powers/power ratios)
metrics_pipes: Metrics pipes for streaming metrics over time for each simulation
metric_config: Metric config (a dictionary that describes how to plot/group the real-time metrics)
"""
cost_dmap: "hv.DynamicMap"
simulations_panels: Dict[str, "pn.layout.Panel"]
costs_pipe: "Pipe"
simulations_pipes: Dict[str, Tuple["Pipe", "Pipe", "Pipe"]]
metric_config: Optional[Dict[str, List[str]]] = None
metrics_panels: Optional[Dict[str, "hv.DynamicMap"]] = None
metrics_pipes: Optional[Dict[str, Dict[str, "Pipe"]]] = None
@fix_dataclass_init_docs
@dataclasses.dataclass
class OptRecord:
"""An optimization record
We need an object to hold the history, which includes a list of costs (we avoid the term loss
as it may be related to denoted
Attributes:
costs: List of costs
params: Params (:math:`\rho`) transformed into the design
metrics: An xarray for metrics with dimensions :code:`name`, :code:`metric`, :code:`iteration`
eps: An xarray for relative permittivity with dimensions :code:`name`, :code:`x`, :code:`y`
fields: An xarray for a selected field component with dimensions :code:`name`, :code:`x`, :code:`y`
"""
costs: np.ndarray
params: jnp.ndarray
metrics: xarray.DataArray
eps: xarray.DataArray
fields: xarray.DataArray
def opt_run(opt_problem: Union[OptProblem, List[OptProblem]], init_params: np.ndarray, num_iters: int,
pbar: Optional[Callable] = None, step_size: float = 1, viz_interval: int = 0, metric_interval: int = 0,
viz: Optional[OptViz] = None, backend: str = 'cpu',
eps_interval: int = 0, field_interval: int = 0) -> OptRecord:
"""Run the optimization.
The optimization can be done over multiple simulations as long as those simulations
share the same set of params provided by :code:`init_params`.
Args:
opt_problem: An :code:`OptProblem` or list of :code:`OptProblem`'s. If a list is provided,
the optimization optimizes the sum of all objective functions.
If the user wants to weight the objective functions, weights must be inlcuded in the objective function
definition itself, but we may provide support for this feature at a later time if needed.
init_params: Initial parameters for the optimizer (:code:`eps` if :code:`None`)
num_iters: Number of iterations to run
pbar: Progress bar to keep track of optimization progress with ideally a simple tqdm interface
step_size: For the Adam update, specify the step size needed.
viz_interval: The optimization intermediate results are recorded every :code:`record_interval` steps
(default of 0 means do not visualize anything)
metric_interval: The interval over which a recorded object (e.g. metric, param)
are recorded in a given :code:`OptProblem` (default of 0 means do not record anything).
viz: The :code:`OptViz` object required for visualizing the optimization in real time.
backend: Recommended backend for :code:`ndim == 2` is :code:`'cpu'` and :code:`ndim == 3` is :code:`'gpu'`
eps_interval: Whether to record the eps at the specified :code:`eps_interval`.
Beware, this can use up a lot of memory during the opt so use judiciously.
field_interval: Whether to record the field at the specified :code:`field_interval`.
Beware, this can use up a lot of memory during the opt so use judiciously.
Returns:
A tuple of the final eps distribution (:code:`transform_fn(p)`) and parameters :code:`p`
"""
opt_init, opt_update, get_params = adam(step_size=step_size)
opt_state = opt_init(init_params)
# define opt_problems
opt_problems = [opt_problem] if isinstance(opt_problem, OptProblem) else opt_problem
n_problems = len(opt_problems)
# opt problems that include both an FDFD sim and a source sim
sim_opt_problems = [op for op in opt_problems if op.sim is not None and op.source is not None]
if viz is not None:
if not len(viz.simulations_pipes) == len(sim_opt_problems):
raise ValueError("Number of viz_pipes must match number of opt problems")
# Define the simulation and objective function acting on parameters rho
solve_fn = [None if (op.source is None or op.sim is None) else op.fn for op in opt_problems]
def overall_cost_fn(rho: jnp.ndarray):
evals = [op.cost_fn(s(rho)) if s is not None else op.cost_fn(rho) for op, s in zip(opt_problems, solve_fn)]
return jnp.array([obj for obj, _ in evals]).sum() / n_problems, [aux for _, aux in evals]
# Define a compiled update step
def step_(current_step, state):
vaux, g = jax.value_and_grad(overall_cost_fn, has_aux=True)(get_params(state))
v, aux = vaux
return v, opt_update(current_step, g, state), aux
def _update_eps(state):
rho = get_params(state)
for op in opt_problems:
op.sim.eps = np.asarray(jax.lax.stop_gradient(op.transform_fn(rho)))
step = jax.jit(step_, backend=backend)
iterator = pbar(range(num_iters)) if pbar is not None else range(num_iters)
costs = []
history = defaultdict(list)
for i in iterator:
v, opt_state, data = step(i, opt_state)
_update_eps(opt_state)
for sop, sparams_fields in zip(sim_opt_problems, data):
sim = sop.sim
sparams, e, h = sim.decorate(*sparams_fields)
hz = np.asarray(h[2]).squeeze().T
if viz_interval > 0 and i % viz_interval == 0 and viz is not None:
eps_pipe, field_pipe, power_pipe = viz.simulations_pipes[sim.name]
eps_pipe.send((sim.eps.T - np.min(sim.eps)) / (np.max(sim.eps) - np.min(sim.eps)))
field_pipe.send(hz.real / np.max(hz.real))
power = np.abs(hz) ** 2
power_pipe.send(power / np.max(power))
if metric_interval > 0 and i % metric_interval == 0 and viz is not None:
metrics = sop.metrics_fn(sparams)
for metric_name, metric_value in metrics.items():
history[f'{metric_name}/{sop.sim.name}'].append(metric_value)
for title in viz.metrics_pipes[sop.sim.name]:
viz.metrics_pipes[sop.sim.name][title].send(
xarray.DataArray(
data=np.asarray([history[f'{metric_name}/{sop.sim.name}']
for metric_name in viz.metric_config[title]]),
coords={
'metric': viz.metric_config[title],
'iteration': np.arange(i + 1)
},
dims=['metric', 'iteration'],
name=title
)
)
if eps_interval > 0 and i % eps_interval == 0:
history[f'eps/{sop.sim.name}'].append((i, sop.sim.eps))
if field_interval > 0 and i % field_interval == 0:
history[f'field/{sop.sim.name}'].append((i, hz.T))
iterator.set_description(f"𝓛: {v:.5f}")
costs.append(jax.lax.stop_gradient(v))
if viz is not None:
viz.costs_pipe.send(np.asarray(costs))
_update_eps(opt_state)
all_metric_names = sum([metric_names for _, metric_names in viz.metric_config.items()], [])
metrics = xarray.DataArray(
data=np.array([[history[f'{metric_name}/{sop.sim.name}']
for metric_name in all_metric_names] for sop in sim_opt_problems]),
coords={
'name': [sop.sim.name for sop in sim_opt_problems],
'metric': all_metric_names,
'iteration': np.arange(num_iters)
},
dims=['name', 'metric', 'iteration'],
name='metrics'
) if sim_opt_problems and metric_interval != 0 else []
eps = xarray.DataArray(
data=np.array([[eps for _, eps in history[f'eps/{sop.sim.name}']] if eps_interval > 0 else []
for sop in sim_opt_problems]),
coords={
'name': [sop.sim.name for sop in sim_opt_problems],
'iteration': [it for it, _ in history[f'eps/{sim_opt_problems[0].sim.name}']],
'x': np.arange(sim_opt_problems[0].sim.shape[0]),
'y': np.arange(sim_opt_problems[0].sim.shape[1]),
},
dims=['name', 'iteration', 'x', 'y'],
name='eps'
) if sim_opt_problems and eps_interval != 0 else []
fields = xarray.DataArray(
data=np.asarray([[field for _, field in history[f'field/{sop.sim.name}']] if field_interval > 0 else []
for sop in sim_opt_problems]),
coords={
'name': [sop.sim.name for sop in sim_opt_problems],
'iteration': [it for it, _ in history[f'field/{sim_opt_problems[0].sim.name}']],
'x': np.arange(sim_opt_problems[0].sim.shape[0]),
'y': np.arange(sim_opt_problems[0].sim.shape[1]),
},
dims=['name', 'iteration', 'x', 'y'],
name='fields'
) if sim_opt_problems and field_interval != 0 else []
return OptRecord(costs=np.asarray(costs), params=get_params(opt_state), metrics=metrics, eps=eps, fields=fields)
def opt_viz(opt_problem: Union[OptProblem, List[OptProblem]], metric_config: Dict[str, List[str]]) -> OptViz:
"""Optimization visualization panel
Args:
opt_problem: An :code:`OptProblem` or list of :code:`OptProblem`'s.
metric_config: A dictionary of titles mapped to lists of metrics to plot in the graph (for overlay)
Returns:
A tuple of visualization panel, loss curve pipe, and visualization pipes
"""
opt_problems = [opt_problem] if isinstance(opt_problem, OptProblem) else opt_problem
viz_panel_pipes = {op.sim.name: op.sim.viz_panel()
for op in opt_problems if op.sim is not None and op.source is not None}
costs_pipe = Pipe(data=[])
metrics_panel_pipes = {op.sim.name: scalar_metrics_viz(metric_config=metric_config)
for op in opt_problems if op.sim is not None and op.source is not None}
return OptViz(
cost_dmap=hv.DynamicMap(hv.Curve, streams=[costs_pipe]).opts(title='Cost Fn (𝓛)'),
simulations_panels={name: v[0] for name, v in viz_panel_pipes.items()},
costs_pipe=costs_pipe,
simulations_pipes={name: v[1] for name, v in viz_panel_pipes.items()},
metrics_panels={name: m[0] for name, m in metrics_panel_pipes.items()},
metrics_pipes={name: m[1] for name, m in metrics_panel_pipes.items()},
metric_config=metric_config
)
|
import os
import directory
from STAPLERerror import STAPLERerror
from STAPLERerror import VirtualIOError
from GenericBase import GenericBase
import utils
class fastx_toolkit_generic_compressable(GenericBase):
"""Generic class with method for parsing fastx toolkit IO parameters.
Only single type of output file is expected (but can be
uncompressed or compressed if -z parameter is present).
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
def _select_IO(self, out_cmd, in_dir, out_dir):
"""Infers the input and output file paths.
This method must keep the directory objects up to date of the file
edits!
Parameters:
in_cmd: A dict containing the command line.
in_dir: Input directory (instance of filetypes.Directory).
out_dir: Output directory (instance of filetypes.Directory).
Returns:
out_cmd: Dict containing the output commands
command_identifier: Input file name based identifier for the current command
Raises:
VirtualIOError: No valid input file can be found.
"""
IO_files = {}
file_names = set()
for fl in in_dir.files:
if self.name not in fl.users:
if utils.splitext(fl.name)[-1] in self.input_types:
IO_files['-i'] = os.path.join(in_dir.path, fl.name)
command_ids = [utils.infer_path_id(IO_files['-i'])]
in_dir.use_file(fl.name, self.name)
assert len(self.output_types) < 2, 'Several output ' \
'types, override ' \
'this method!'
# If -z parameter is present in the input, output file will
# be compressed
if '-z' in out_cmd:
output_name = utils.splitext(fl.name)[0] + \
self.output_types[0] + '.gz'
else:
output_name = utils.splitext(fl.name)[0] + \
self.output_types[0]
output_path = os.path.join(out_dir.path, output_name)
IO_files['-o'] = output_path
file_names.add(output_name)
out_dir.add_file(output_name)
break
if not IO_files:
raise VirtualIOError('No more unused input files')
out_cmd.update(IO_files)
return out_cmd, command_ids
class fastx_toolkit_generic_compressable_fastx(GenericBase):
"""Generic class with method for parsing fastx toolkit IO parameters.
Similar to fastx_toolkit_generic_compressable, but fasta or fastq output
is expected (either can be compressed).
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
def _select_IO(self, out_cmd, in_dir, out_dir):
"""Infers the input and output file paths.
This method must keep the directory objects up to date of the file
edits!
Parameters:
in_cmd: A dict containing the command line.
in_dir: Input directory (instance of filetypes.Directory).
out_dir: Output directory (instance of filetypes.Directory).
Returns:
out_cmd: Dict containing the output commands
command_identifier: Input file name based identifier for the current command
Raises:
VirtualIOError: No valid input file can be found.
"""
IO_files = {}
file_names = set()
for fl in in_dir.files:
if self.name not in fl.users:
if utils.splitext(fl.name)[-1] in self.input_types:
IO_files['-i'] = os.path.join(in_dir.path, fl.name)
command_ids = [utils.infer_path_id(IO_files['-i'])]
in_dir.use_file(fl.name, self.name)
# Output filename extension is the same as input filename
# extension
output_file_extension = utils.splitext(IO_files['-i'])
# If -z parameter is present in the input, output file will
# be compressed
if '-z' in out_cmd:
output_name = utils.splitext(fl.name)[0] + \
output_file_extension + '.gz'
else:
output_name = utils.splitext(fl.name)[0] + \
output_file_extension
output_path = os.path.join(out_dir.path, output_name)
IO_files['-o'] = output_path
file_names.add(output_name)
out_dir.add_file(output_name)
break
if not IO_files:
raise VirtualIOError('No more unused input files')
out_cmd.update(IO_files)
return out_cmd, command_ids
class fasta_formatter(GenericBase):
"""Class for using FASTX-toolkit command fasta_formatter.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fasta_formatter'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq', '.tab']
hidden_mandatory_args = ['-i', '-o']
user_optional_args = ['-w', '-t', '-e']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
def _select_IO(self, out_cmd, in_dir, out_dir):
"""Infers the input and output file paths.
This method must keep the directory objects up to date of the file
edits!
Parameters:
in_cmd: A dict containing the command line.
in_dir: Input directory (instance of filetypes.Directory).
out_dir: Output directory (instance of filetypes.Directory).
Returns:
out_cmd: Dict containing the output commands
command_identifier: Input file name based identifier for the current command
Raises:
VirtualIOError: No valid input file can be found.
"""
IO_files = {}
file_names = set()
for fl in in_dir.files:
if self.name not in fl.users:
if utils.splitext(fl.name)[-1] in self.input_types:
IO_files['-i'] = os.path.join(in_dir.path, fl.name)
command_ids = [utils.infer_path_id(IO_files['-i'])]
in_dir.use_file(fl.name, self.name)
# Output filename extension is the same as input filename
# extension, except when -t parameter is included the
# output format is .tab
if '-t' in out_cmd:
output_file_extension = '.tab'
else:
output_file_extension = utils.splitext(IO_files['-i'])
# If -z parameter is present in the input, output file will
# be compressed
if '-z' in out_cmd:
output_name = utils.splitext(fl.name)[0] + \
output_file_extension + '.gz'
else:
output_name = utils.splitext(fl.name)[0] + \
output_file_extension
output_path = os.path.join(out_dir.path, output_name)
IO_files['-o'] = output_path
file_names.add(output_name)
out_dir.add_file(output_name)
break
if not IO_files:
raise VirtualIOError('No more unused input files')
out_cmd.update(IO_files)
return out_cmd, command_ids
class fasta_nucleotide_changer(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fasta_nucleotide_changer.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fasta_nucleotide_changer'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o']
user_optional_args = ['-r', '-d', '-z', '-v']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastq_quality_boxplot_graph(GenericBase):
"""Class for using FASTX-toolkit command fastq_quality_boxplot_graph.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastq_quality_boxplot_graph.sh'
input_types = {'.fastx_quality_stats'}
output_types = ['.png']
hidden_mandatory_args = ['-i', '-o']
user_optional_args = []
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
def _format_cmd(self, cmd):
"""Determines the output file name and type.
Also adds the -t argument which based on file name.
Parameters:
cmd: Parsed command line.
Returns:
cmd: Command line with -o set to point to a file in a dir instead a dir
file_names: Name(s) of the files this command outputs
"""
assert len(self.output_types) == 1, 'Many output types, override this function'
file_name = cmd['-i']
file_name = utils.splitext(file_name)[0] + self.output_types[0]
cmd['-o'] = os.path.join(cmd['-o'], file_name)
cmd['-t'] = file_name
file_names = [os.path.basename(file_name)]
return cmd, file_names
class fastq_quality_filter(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastq_quality_filter.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastq_quality_filter'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o', '-q', '-p']
user_optional_args = ['-v', '-z']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastq_quality_trimmer(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastq_quality_trimmer.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastq_quality_trimmer'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o', '-t']
user_optional_args = ['-l', '-v', '-Q']
help_description = """
Tested with fastx-tookit v. 0.0.14
"""
class fastq_to_fasta(fastx_toolkit_generic_compressable):
"""Class for parallelizing fastq_to_fasta.
Parameters:
in_cmd: String containing a command line
in_dir: Directory object containing input files
out_dir: Directory object containing output files
NOTICE! Keep the directory objects up to date about file edits!
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
output_types: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
user_mandatory_args: Args the user must provide.
remove_user_args: Args that will be removed from the final command.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
file_names: Names of output files.
command_ids: File names of input file(s) with no file extensions.
Methods:
get_cmd: Method for getting the final cmd line string for output.
"""
name = 'stapler_fastx_toolkit_fastq_to_fasta'
input_types = {'.fastq'}
output_types = ['.fasta']
hidden_mandatory_args = ['-i', '-o']
user_mandatory_args = []
remove_user_args = user_mandatory_args
user_optional_args = ['-r', '-n', '-v', '-z']
parallelizable = True
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastx_artifacts_filter(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastx_artifacts_filter.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_artifacts_filter'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o']
user_mandatory_args = []
user_optional_args = ['-z']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastx_clipper(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastx_clipper.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_clipper'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o']
user_optional_args = ['-a', '-l', '-d', '-c', '-C', '-k', '-n', '-v', '-z',
'-D']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastx_collapser(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastx_collapser.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_collapser'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o']
user_mandatory_args = []
user_optional_args = []
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastx_nucleotide_distribution_graph(fastq_quality_boxplot_graph):
"""Class for FASTX-toolkit command fastx_nucleotide_distribution_graph.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_nucleotide_distribution_graph.sh'
class fastx_quality_stats(GenericBase):
"""Class for using FASTX-toolkit command fastx_quality_stats.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_quality_stats'
input_types = {'.fasta', '.fastq'}
output_types = ['.fastx_quality_stats']
hidden_mandatory_args = ['-i', '-o']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastx_renamer(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastx_renamer.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_trimmer'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o']
user_mandatory_args = ['-n']
user_optional_args = ['-z']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastx_reverse_complement(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastx_reverse_complement.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_reverse_complement'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o']
user_optional_args = ['-z']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
class fastx_trimmer(fastx_toolkit_generic_compressable_fastx):
"""Class for using FASTX-toolkit command fastx_trimmer.
Attributes:
name: Name of the function.
input_type: Input types accepted by this application.
_output_type: List of output types produced by the application.
mandatory_args: Args the user be provided in in_cmd when initializing.
optional_args: Args that may be part of the command line.
in_cmd: Command entered by user.
parsed_cmd: Final output command as option:value dict.
id: Bare name of input file (without the possible ending)
file_names: Names of output files
Methods:
_cmd_parse: Turns a command line into argument-value pairs.
_validate: Classmethod for validating command lines.
get_cmd: Method for getting the final cmd line string for output.
_set_IO: Determines the output file name and type.
_parse_id: Returns the bare input file name
"""
name = 'stapler_fastx_toolkit_fastx_trimmer'
input_types = {'.fasta', '.fastq'}
output_types = ['.fasta', '.fastq']
hidden_mandatory_args = ['-i', '-o']
user_optional_args = ['-f', '-l', '-z']
help_description = '''
Tested with fastx-tookit v. 0.0.14
'''
def _validate(self, parsed_cmd):
"""Validates the command line.
Raises STAPLERerror if validation is unsuccessfull
Args:
parsed_cmd: Dict of arguments entered by user
Raises:
STAPLERerror if validation is unsuccessful
"""
for ma in self.hidden_mandatory_args:
if ma not in parsed_cmd:
raise STAPLERerror('The command line does not contain '
'all the mandatory arguments '
'{0}:\n{1}'.format(self.hidden_mandatory_args,
' '.join(parsed_cmd)))
for cmd in parsed_cmd:
if cmd not in self.hidden_mandatory_args and cmd not in self.user_optional_args:
raise STAPLERerror('Unknown option: {0}\n'
'on command line:\n{1}'.format(cmd, self.in_cmd))
|
<reponame>Undo1/Smokey-McSmokeface
import random
from threading import Thread, Lock
from parsing import *
from datahandling import *
from metasmoke import Metasmoke
from globalvars import GlobalVars
import os
import re
import requests
from datetime import datetime
from utcdate import UtcDate
from apigetpost import api_get_post
from spamhandling import handle_spam, handle_user_with_all_spam
from termcolor import colored
from findspam import FindSpam
from deletionwatcher import DeletionWatcher
from ChatExchange.chatexchange.messages import Message
# Please note: If new !!/ commands are added or existing ones are modified, don't forget to
# update the wiki at https://github.com/Charcoal-SE/SmokeDetector/wiki/Commands.
add_latest_message_lock = Lock()
def post_message_in_room(room_id_str, msg, length_check=True):
if room_id_str == GlobalVars.charcoal_room_id:
GlobalVars.charcoal_hq.send_message(msg, length_check)
elif room_id_str == GlobalVars.meta_tavern_room_id:
GlobalVars.tavern_on_the_meta.send_message(msg, length_check)
elif room_id_str == GlobalVars.socvr_room_id:
GlobalVars.socvr.send_message(msg, length_check)
def is_smokedetector_message(user_id, room_id):
return user_id == GlobalVars.smokeDetector_user_id[room_id]
def add_to_listen_if_edited(host, message_id):
if host + str(message_id) not in GlobalVars.listen_to_these_if_edited:
GlobalVars.listen_to_these_if_edited.append(host + str(message_id))
if len(GlobalVars.listen_to_these_if_edited) > 500:
GlobalVars.listen_to_these_if_edited = GlobalVars.listen_to_these_if_edited[-500:]
def print_chat_message(ev):
message = colored("Chat message in " + ev.data["room_name"] + " (" + str(ev.data["room_id"]) + "): \"", attrs=['bold'])
message += ev.data['content']
message += "\""
print message + colored(" - " + ev.data['user_name'], attrs=['bold'])
def special_room_watcher(ev, wrap2):
if ev.type_id != 1:
return
ev_user_id = str(ev.data["user_id"])
content_source = ev.message.content_source
if is_smokedetector_message(ev_user_id, GlobalVars.charcoal_room_id):
post_site_id = fetch_post_id_and_site_from_msg_content(content_source)
post_url = fetch_post_url_from_msg_content(content_source)
if post_site_id is not None and post_url is not None:
t_check_websocket = Thread(target=DeletionWatcher.check_if_report_was_deleted, args=(post_site_id, post_url, ev.message))
t_check_websocket.daemon = True
t_check_websocket.start()
def watcher(ev, wrap2):
if ev.type_id != 1 and ev.type_id != 2:
return
if ev.type_id == 2 and (wrap2.host + str(ev.message.id)) not in GlobalVars.listen_to_these_if_edited:
return
print_chat_message(ev)
ev_room = str(ev.data["room_id"])
ev_user_id = str(ev.data["user_id"])
ev_room_name = ev.data["room_name"].encode('utf-8')
if ev.type_id == 2:
ev.message = Message(ev.message.id, wrap2)
content_source = ev.message.content_source
message_id = ev.message.id
if is_smokedetector_message(ev_user_id, ev_room):
add_latest_message_lock.acquire()
add_latest_smokedetector_message(ev_room, message_id)
add_latest_message_lock.release()
post_site_id = fetch_post_id_and_site_from_msg_content(content_source)
post_url = fetch_post_url_from_msg_content(content_source)
if post_site_id is not None and (ev_room == GlobalVars.meta_tavern_room_id or ev_room == GlobalVars.socvr_room_id):
t_check_websocket = Thread(target=DeletionWatcher.check_if_report_was_deleted, args=(post_site_id, post_url, ev.message))
t_check_websocket.daemon = True
t_check_websocket.start()
message_parts = re.split('[ ,]+', content_source)
ev_user_name = ev.data["user_name"]
ev_user_link = "//chat.{host}/users/{user_id}".format(host=wrap2.host, user_id=ev.user.id)
if ev_user_name != "SmokeDetector":
GlobalVars.users_chatting[ev_room].append((ev_user_name, ev_user_link))
shortcut_messages = []
if message_parts[0].lower() == "sd":
message_parts = preprocess_shortcut_command(content_source).split(" ")
latest_smokedetector_messages = GlobalVars.latest_smokedetector_messages[ev_room]
commands = message_parts[1:]
if len(latest_smokedetector_messages) == 0:
ev.message.reply("I don't have any messages posted after the latest reboot.")
return
if len(commands) > len(latest_smokedetector_messages):
ev.message.reply("I've only posted {} messages since the latest reboot; that's not enough to execute all commands. No commands were executed.".format(len(latest_smokedetector_messages)))
return
for i in xrange(0, len(commands)):
shortcut_messages.append(u":{message} {command_name}".format(message=latest_smokedetector_messages[-(i + 1)], command_name=commands[i]))
reply = ""
amount_none = 0
amount_skipped = 0
amount_unrecognized = 0
length = len(shortcut_messages)
for i in xrange(0, length):
current_message = shortcut_messages[i]
if length > 1:
reply += str(i + 1) + ". "
reply += u"[{0}] ".format(current_message.split(" ")[0])
if current_message.split(" ")[1] != "-":
result = handle_commands(current_message.lower(), current_message.split(" "), ev_room, ev_room_name, ev_user_id, ev_user_name, wrap2, current_message, message_id)
r = result
if type(result) == tuple:
result = result[1]
if result is not None and result is not False:
reply += result + os.linesep
elif result is None:
reply += "<processed without return value>" + os.linesep
amount_none += 1
elif result is False or r[0] is False:
reply += "<unrecognized command>" + os.linesep
amount_unrecognized += 1
else:
reply += "<skipped>" + os.linesep
amount_skipped += 1
if amount_unrecognized == length:
add_to_listen_if_edited(wrap2.host, message_id)
if amount_none + amount_skipped + amount_unrecognized == length:
reply = ""
reply = reply.strip()
if reply != "":
message_with_reply = u":{} {}".format(message_id, reply)
if len(message_with_reply) <= 500 or "\n" in reply:
ev.message.reply(reply, False)
else:
result = handle_commands(content_source.lower(), message_parts, ev_room, ev_room_name, ev_user_id, ev_user_name, wrap2, content_source, message_id)
if type(result) != tuple:
result = (True, result)
if result[1] is not None:
if wrap2.host + str(message_id) in GlobalVars.listen_to_these_if_edited:
GlobalVars.listen_to_these_if_edited.remove(wrap2.host + str(message_id))
message_with_reply = u":{} {}".format(message_id, result[1])
if len(message_with_reply) <= 500 or "\n" in result[1]:
ev.message.reply(result[1], False)
if result[0] is False:
add_to_listen_if_edited(wrap2.host, message_id)
def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user_id, ev_user_name, wrap2, content, message_id):
if content_lower.startswith("!!/parse") \
and is_privileged(ev_room, ev_user_id, wrap2):
string_to_parse = content[9:]
print string_to_parse
response = requests.get("http://localhost:8000/?q=" + string_to_parse)
print response.text
GlobalVars.charcoal_hq.send_message(' ' + ('\n ').join(response.text.split('\n')), False)
return
message_url = "//chat.{host}/transcript/message/{id}#{id}".format(host=wrap2.host, id=message_id)
second_part_lower = "" if len(message_parts) < 2 else message_parts[1].lower()
if second_part_lower in ["f", "notspam"]:
second_part_lower = "fp-"
if second_part_lower in ["k", "spam", "rude", "abuse", "abusive", "offensive"]:
second_part_lower = "tpu-"
if second_part_lower == "n":
second_part_lower = "naa-"
if re.compile("^:[0-9]{4,}$").search(message_parts[0]):
msg_id = int(message_parts[0][1:])
msg = wrap2.get_message(msg_id)
msg_content = msg.content_source
quiet_action = ("-" in second_part_lower)
if str(msg.owner.id) != GlobalVars.smokeDetector_user_id[ev_room] or msg_content is None:
return
post_url = fetch_post_url_from_msg_content(msg_content)
post_site_id = fetch_post_id_and_site_from_msg_content(msg_content)
if post_site_id is not None:
post_type = post_site_id[2]
else:
post_type = None
if (second_part_lower.startswith("false") or second_part_lower.startswith("fp")) \
and is_privileged(ev_room, ev_user_id, wrap2):
if post_site_id is None:
return "That message is not a report."
t_metasmoke = Thread(target=Metasmoke.send_feedback_for_post,
args=(post_url, second_part_lower, ev_user_name, ev_user_id, ))
t_metasmoke.start()
add_false_positive((post_site_id[0], post_site_id[1]))
user_added = False
user_removed = False
url_from_msg = fetch_owner_url_from_msg_content(msg_content)
user = None
if url_from_msg is not None:
user = get_user_from_url(url_from_msg)
if second_part_lower.startswith("falseu") or second_part_lower.startswith("fpu"):
if user is not None:
add_whitelisted_user(user)
user_added = True
if "Blacklisted user:" in msg_content:
if user is not None:
remove_blacklisted_user(user)
user_removed = True
if post_type == "question":
if user_added and not quiet_action:
return "Registered question as false positive and whitelisted user."
elif user_removed and not quiet_action:
return "Registered question as false positive and removed user from the blacklist."
elif not quiet_action:
return "Registered question as false positive."
elif post_type == "answer":
if user_added and not quiet_action:
return "Registered answer as false positive and whitelisted user."
elif user_removed and not quiet_action:
return "Registered answer as false positive and removed user from the blacklist."
elif not quiet_action:
return "Registered answer as false positive."
try:
msg.delete()
except:
pass
if (second_part_lower.startswith("true") or second_part_lower.startswith("tp")) \
and is_privileged(ev_room, ev_user_id, wrap2):
if post_site_id is None:
return "That message is not a report."
t_metasmoke = Thread(target=Metasmoke.send_feedback_for_post,
args=(post_url, second_part_lower, ev_user_name, ev_user_id, ))
t_metasmoke.start()
user_added = False
if second_part_lower.startswith("trueu") or second_part_lower.startswith("tpu"):
url_from_msg = fetch_owner_url_from_msg_content(msg_content)
if url_from_msg is not None:
user = get_user_from_url(url_from_msg)
if user is not None:
add_blacklisted_user(user, message_url, "http:" + post_url)
user_added = True
if post_type == "question":
if quiet_action:
return None
if user_added:
return "Blacklisted user and registered question as true positive."
return "Recorded question as true positive in metasmoke. Use `tpu` or `trueu` if you want to blacklist a user."
elif post_type == "answer":
if quiet_action:
return None
if user_added:
return "Blacklisted user."
return "Recorded answer as true positive in metasmoke. If you want to blacklist the poster of the answer, use `trueu` or `tpu`."
if second_part_lower.startswith("ignore") and is_privileged(ev_room, ev_user_id, wrap2):
if post_site_id is None:
return "That message is not a report."
t_metasmoke = Thread(target=Metasmoke.send_feedback_for_post,
args=(post_url, second_part_lower, ev_user_name, ev_user_id,))
t_metasmoke.start()
add_ignored_post(post_site_id[0:2])
if not quiet_action:
return "Post ignored; alerts about it will no longer be posted."
else:
return None
if second_part_lower.startswith("naa") and is_privileged(ev_room, ev_user_id, wrap2):
if post_site_id is None:
return "That message is not a report."
if post_type != "answer":
return "That report was a question; questions cannot be marked as NAAs."
t_metasmoke = Thread(target=Metasmoke.send_feedback_for_post,
args=(post_url, second_part_lower, ev_user_name, ev_user_id, ))
t_metasmoke.start()
add_ignored_post(post_site_id[0:2])
if quiet_action:
return None
return "Recorded answer as an NAA in metasmoke."
if (second_part_lower.startswith("delete") or second_part_lower.startswith("remove") or second_part_lower.startswith("gone") or second_part_lower.startswith("poof") or second_part_lower == "del") and is_privileged(ev_room, ev_user_id, wrap2):
try:
msg.delete()
except:
pass # couldn't delete message
if second_part_lower.startswith("postgone") and is_privileged(ev_room, ev_user_id, wrap2):
edited = edited_message_after_postgone_command(msg_content)
if edited is None:
return "That's not a report."
msg.edit(edited)
return None
if second_part_lower.startswith("why"):
post_info = fetch_post_id_and_site_from_msg_content(msg_content)
if post_info is None:
post_info = fetch_user_from_allspam_report(msg_content)
if post_info is None:
return "That's not a report."
why = get_why_allspam(post_info)
if why is not None or why != "":
return why
else:
post_id, site, _ = post_info
why = get_why(site, post_id)
if why is not None or why != "":
return why
return "There is no `why` data for that user (anymore)."
if content_lower.startswith("!!/addblu") \
and is_privileged(ev_room, ev_user_id, wrap2):
uid, val = get_user_from_list_command(content_lower)
if uid > -1 and val != "":
add_blacklisted_user((uid, val), message_url, "")
return "User blacklisted (`{}` on `{}`).".format(uid, val)
elif uid == -2:
return "Error: {}".format(val)
else:
return "Invalid format. Valid format: `!!/addblu profileurl` *or* `!!/addblu userid sitename`."
if content_lower.startswith("!!/rmblu") \
and is_privileged(ev_room, ev_user_id, wrap2):
uid, val = get_user_from_list_command(content_lower)
if uid > -1 and val != "":
if remove_blacklisted_user((uid, val)):
return "User removed from blacklist (`{}` on `{}`).".format(uid, val)
else:
return "User is not blacklisted."
elif uid == -2:
return "Error: {}".format(val)
else:
return False, "Invalid format. Valid format: `!!/rmblu profileurl` *or* `!!/rmblu userid sitename`."
if content_lower.startswith("!!/isblu"):
uid, val = get_user_from_list_command(content_lower)
if uid > -1 and val != "":
if is_blacklisted_user((uid, val)):
return "User is blacklisted (`{}` on `{}`).".format(uid, val)
else:
return "User is not blacklisted (`{}` on `{}`).".format(uid, val)
elif uid == -2:
return "Error: {}".format(val)
else:
return False, "Invalid format. Valid format: `!!/isblu profileurl` *or* `!!/isblu userid sitename`."
if content_lower.startswith("!!/addwlu") \
and is_privileged(ev_room, ev_user_id, wrap2):
uid, val = get_user_from_list_command(content_lower)
if uid > -1 and val != "":
add_whitelisted_user((uid, val))
return "User whitelisted (`{}` on `{}`).".format(uid, val)
elif uid == -2:
return "Error: {}".format(val)
else:
return False, "Invalid format. Valid format: `!!/addwlu profileurl` *or* `!!/addwlu userid sitename`."
if content_lower.startswith("!!/rmwlu") \
and is_privileged(ev_room, ev_user_id, wrap2):
uid, val = get_user_from_list_command(content_lower)
if uid != -1 and val != "":
if remove_whitelisted_user((uid, val)):
return "User removed from whitelist (`{}` on `{}`).".format(uid, val)
else:
return "User is not whitelisted."
elif uid == -2:
return "Error: {}".format(val)
else:
return False, "Invalid format. Valid format: `!!/rmwlu profileurl` *or* `!!/rmwlu userid sitename`."
if content_lower.startswith("!!/iswlu"):
uid, val = get_user_from_list_command(content_lower)
if uid > -1 and val != "":
if is_whitelisted_user((uid, val)):
return "User is whitelisted (`{}` on `{}`).".format(uid, val)
else:
return "User is not whitelisted (`{}` on `{}`).".format(uid, val)
elif uid == -2:
return "Error: {}".format(val)
else:
return False, "Invalid format. Valid format: `!!/iswlu profileurl` *or* `!!/iswlu userid sitename`."
if (content_lower.startswith("!!/allspam") or content_lower.startswith("!!/reportuser")) and is_privileged(ev_room, ev_user_id, wrap2):
if len(message_parts) != 2:
return False, "1 argument expected"
url = message_parts[1]
user = get_user_from_url(url)
if user is None:
return "That doesn't look like a valid user URL."
why = u"User manually reported by *{}* in room *{}*.\n".format(ev_user_name, ev_room_name.decode('utf-8'))
handle_user_with_all_spam(user, why)
return None
if content_lower.startswith("!!/report") \
and is_privileged(ev_room, ev_user_id, wrap2):
crn, wait = can_report_now(ev_user_id, wrap2.host)
if not crn:
return "You can execute the !!/report command again in {} seconds. " \
"To avoid one user sending lots of reports in a few commands and slowing SmokeDetector down due to rate-limiting, " \
"you have to wait 30 seconds after you've reported multiple posts using !!/report, even if your current command just has one URL. " \
"(Note that this timeout won't be applied if you only used !!/report for one post)".format(wait)
if len(message_parts) < 2:
return False, "Not enough arguments."
output = []
index = 0
urls = list(set(message_parts[1:]))
if len(urls) > 5:
return False, "To avoid SmokeDetector reporting posts too slowly, " \
"you can report at most 5 posts at a time. " \
"This is to avoid SmokeDetector's chat messages getting rate-limited too much, " \
"which would slow down reports."
for url in urls:
index += 1
post_data = api_get_post(url)
if post_data is None:
output.append("Post {}: That does not look like a valid post URL.".format(index))
continue
if post_data is False:
output.append("Post {}: Could not find data for this post in the API. It may already have been deleted.".format(index))
continue
user = get_user_from_url(post_data.owner_url)
if user is not None:
add_blacklisted_user(user, message_url, post_data.post_url)
why = u"Post manually reported by user *{}* in room *{}*.\n".format(ev_user_name, ev_room_name.decode('utf-8'))
batch = ""
if len(urls) > 1:
batch = " (batch report: post {} out of {})".format(index, len(urls))
handle_spam(post_data.title, post_data.body, post_data.owner_name, post_data.site, post_data.post_url,
post_data.owner_url, post_data.post_id, ["Manually reported " + post_data.post_type + batch],
post_data.post_type == "answer", why, post_data.owner_rep, post_data.score, post_data.up_vote_count,
post_data.down_vote_count, post_data.question_id)
if 1 < len(urls) > len(output):
add_or_update_multiple_reporter(ev_user_id, wrap2.host, time.time())
if len(output) > 0:
return os.linesep.join(output)
return None
if content_lower.startswith("!!/wut"):
return "Whaddya mean, 'wut'? Humans..."
if content_lower.startswith("!!/lick"):
return "*licks ice cream cone*"
if content_lower.startswith("!!/alive"):
if ev_room == GlobalVars.charcoal_room_id:
return 'Of course'
elif ev_room == GlobalVars.meta_tavern_room_id or ev_room == GlobalVars.socvr_room_id:
return random.choice(['Yup', 'You doubt me?', 'Of course', '... did I miss something?', 'plz send teh coffee', 'Watching this endless list of new questions *never* gets boring', 'Kinda sorta'])
if content_lower.startswith("!!/rev") or content_lower.startswith("!!/ver"):
return '[{commit_name}](https://github.com/Charcoal-SE/SmokeDetector/commit/{commit_code})'.format(commit_name=GlobalVars.commit_with_author, commit_code=GlobalVars.commit)
if content_lower.startswith("!!/status"):
now = datetime.utcnow()
diff = now - UtcDate.startup_utc_date
minutes, remainder = divmod(diff.seconds, 60)
minute_str = "minutes" if minutes != 1 else "minute"
return 'Running since {time} UTC ({minute_count} {plurality})'.format(time=GlobalVars.startup_utc, minute_count=minutes, plurality=minute_str)
if content_lower.startswith("!!/reboot"):
if is_privileged(ev_room, ev_user_id, wrap2):
post_message_in_room(ev_room, "Goodbye, cruel world")
os._exit(5)
if content_lower.startswith("!!/stappit"):
if is_privileged(ev_room, ev_user_id, wrap2):
post_message_in_room(ev_room, "Goodbye, cruel world")
os._exit(6)
if content_lower.startswith("!!/master"):
if is_privileged(ev_room, ev_user_id, wrap2):
os._exit(8)
if content_lower.startswith("!!/clearbl"):
if is_privileged(ev_room, ev_user_id, wrap2):
if os.path.isfile("blacklistedUsers.txt"):
os.remove("blacklistedUsers.txt")
GlobalVars.blacklisted_users = []
return "Kaboom, blacklisted users cleared."
return "There are no blacklisted users at the moment."
if content_lower.startswith("!!/block") and is_privileged(ev_room, ev_user_id, wrap2):
room_id = message_parts[2] if len(message_parts) > 2 else "all"
timeToBlock = message_parts[1] if len(message_parts) > 1 else "0"
if not timeToBlock.isdigit():
return False, "Invalid duration."
timeToBlock = int(timeToBlock)
timeToBlock = timeToBlock if 0 < timeToBlock < 14400 else 900
GlobalVars.blockedTime[room_id] = time.time() + timeToBlock
which_room = "globally" if room_id == "all" else "in room " + room_id
report = "Reports blocked for {} seconds {}.".format(timeToBlock, which_room)
if room_id != GlobalVars.charcoal_room_id:
GlobalVars.charcoal_hq.send_message(report)
return report
if content_lower.startswith("!!/unblock") and is_privileged(ev_room, ev_user_id, wrap2):
room_id = message_parts[2] if len(message_parts) > 2 else "all"
GlobalVars.blockedTime[room_id] = time.time()
which_room = "globally" if room_id == "all" else "in room " + room_id
report = "Reports unblocked {}.".format(GlobalVars.blockedTime - time.time(), which_room)
if room_id != GlobalVars.charcoal_room_id:
GlobalVars.charcoal_hq.send_message(report)
return report
if content_lower.startswith("!!/errorlogs"):
if is_privileged(ev_room, ev_user_id, wrap2):
count = -1
if len(message_parts) != 2:
return "The !!/errorlogs command requires 1 argument."
try:
count = int(message_parts[1])
except ValueError:
pass
if count == -1:
return "Invalid argument."
logs_part = fetch_lines_from_error_log(count)
post_message_in_room(ev_room, logs_part, False)
if content_lower.startswith("!!/pull"):
if is_privileged(ev_room, ev_user_id, wrap2):
request = requests.get('https://api.github.com/repos/Charcoal-SE/SmokeDetector/git/refs/heads/master')
latest_sha = request.json()["object"]["sha"]
request = requests.get('https://api.github.com/repos/Charcoal-SE/SmokeDetector/commits/{commit_code}/statuses'.format(commit_code=latest_sha))
states = []
for status in request.json():
state = status["state"]
states.append(state)
if "success" in states:
os._exit(3)
elif "error" in states or "failure" in states:
return "CI build failed! :( Please check your commit."
elif "pending" in states or not states:
return "CI build is still pending, wait until the build has finished and then pull again."
if content_lower.startswith("!!/help") or content_lower.startswith("!!/info"):
return "I'm [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector), a bot "\
"that detects spam and offensive posts on the network and posts alerts to chat. "\
"[A command list is available here](https://github.com/Charcoal-SE/SmokeDetector/wiki/Commands)."
if content_lower.startswith("!!/apiquota"):
return "The current API quota remaining is {}.".format(GlobalVars.apiquota)
if content_lower.startswith("!!/whoami"):
if (ev_room in GlobalVars.smokeDetector_user_id):
return "My id for this room is {}.".format(GlobalVars.smokeDetector_user_id[ev_room])
return "I don't know my user ID for this room. (Something is wrong, and it's apnorton's fault.)"
if content_lower.startswith("!!/location"):
return GlobalVars.location
if content_lower.startswith("!!/queuestatus"):
post_message_in_room(ev_room, GlobalVars.bodyfetcher.print_queue(), False)
if content_lower.startswith("!!/blame"):
GlobalVars.users_chatting[ev_room] = list(set(GlobalVars.users_chatting[ev_room])) # Make unique
user_to_blame = random.choice(GlobalVars.users_chatting[ev_room])
return u"It's [{}]({})'s fault.".format(user_to_blame[0], user_to_blame[1])
if content_lower.startswith("!!/coffee"):
return "*brews coffee for @" + ev_user_name.replace(" ", "") + "*"
if content_lower.startswith("!!/tea"):
return "*brews a cup of {choice} tea for @{user}*".format(choice=random.choice(['earl grey', 'green', 'chamomile', 'lemon', 'darjeeling', 'mint', 'jasmine']), user=ev_user_name.replace(" ", ""))
if content_lower.startswith("!!/brownie"):
return "Brown!"
if content_lower.startswith("!!/hats"):
wb_end = datetime(2016, 1, 4, 0, 0, 0)
now = datetime.utcnow()
if wb_end > now:
diff = wb_end - now
hours, remainder = divmod(diff.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
daystr = "days" if diff.days != 1 else "day"
hourstr = "hours" if hours != 1 else "hour"
minutestr = "minutes" if minutes != 1 else "minute"
secondstr = "seconds" if seconds != 1 else "second"
return "HURRY UP AND EARN MORE HATS! Winterbash will be over in {} {}, {} {}, {} {}, and {} {}. :(".format(diff.days, daystr, hours, hourstr, minutes, minutestr, seconds, secondstr)
return "Winterbash is over. :("
if content_lower.startswith("!!/test"):
string_to_test = content[8:]
test_as_answer = False
if content_lower.startswith("!!/test-a"):
string_to_test = content[10:]
test_as_answer = True
if len(string_to_test) == 0:
return "Nothing to test"
result = "> "
reasons, why = FindSpam.test_post(string_to_test, string_to_test, string_to_test, "", test_as_answer, False, 1, 0)
if len(reasons) == 0:
result += "Would not be caught for title, {}, and username.".format("answer" if test_as_answer else "body")
return result
result += ", ".join(reasons).capitalize()
if why is not None and len(why) > 0:
result += "\n----------\n"
result += why
return result
if content_lower.startswith("!!/amiprivileged"):
if is_privileged(ev_room, ev_user_id, wrap2):
return "Yes, you are a privileged user."
return "No, you are not a privileged user."
if content_lower.startswith("!!/notify"):
if len(message_parts) != 3:
return False, "2 arguments expected"
user_id = int(ev_user_id)
chat_site = wrap2.host
room_id = message_parts[1]
if not room_id.isdigit():
return False, "Room ID is invalid."
room_id = int(room_id)
quiet_action = ("-" in message_parts[2])
se_site = message_parts[2].replace('-', '')
response, full_site = add_to_notification_list(user_id, chat_site, room_id, se_site)
if response == 0:
if quiet_action:
return None
return "You'll now get pings from me if I report a post on `{site_name}`, in room `{room_id}` on `chat.{chat_domain}`".format(site_name=se_site, room_id=room_id, chat_domain=chat_site)
elif response == -1:
return "That notification configuration is already registered."
elif response == -2:
return False, "The given SE site does not exist."
if content_lower.startswith("!!/unnotify"):
if len(message_parts) != 3:
return False, "2 arguments expected"
user_id = int(ev_user_id)
chat_site = wrap2.host
room_id = message_parts[1]
if not room_id.isdigit():
return False, "Room ID is invalid."
room_id = int(room_id)
quiet_action = ("-" in message_parts[2])
se_site = message_parts[2].replace('-', '')
response = remove_from_notification_list(user_id, chat_site, room_id, se_site)
if response:
if quiet_action:
return None
return "I will no longer ping you if I report a post on `{site_name}`, in room `{room_id}` on `chat.{chat_domain}`".format(site_name=se_site, room_id=room_id, chat_domain=chat_site)
return "That configuration doesn't exist."
if content_lower.startswith("!!/willibenotified"):
if len(message_parts) != 3:
return False, "2 arguments expected"
user_id = int(ev_user_id)
chat_site = wrap2.host
room_id = message_parts[1]
if not room_id.isdigit():
return False, "Room ID is invalid"
room_id = int(room_id)
se_site = message_parts[2]
will_be_notified = will_i_be_notified(user_id, chat_site, room_id, se_site)
if will_be_notified:
return "Yes, you will be notified for that site in that room."
return "No, you won't be notified for that site in that room."
if content_lower.startswith("!!/allnotificationsites"):
if len(message_parts) != 2:
return False, "1 argument expected"
user_id = int(ev_user_id)
chat_site = wrap2.host
room_id = message_parts[1]
if not room_id.isdigit():
return False, "Room ID is invalid."
sites = get_all_notification_sites(user_id, chat_site, room_id)
if len(sites) == 0:
return "You won't get notified for any sites in that room."
return "You will get notified for these sites:\r\n" + ", ".join(sites)
return False, None # Unrecognized command, can be edited later.
|
<filename>cvnet/models/cls/googlenet.py
# -*- coding: utf-8 -*-
"""
@author:XuMing(<EMAIL>)
@description: GoogLeNet model
Inception块相当于一个有4条线路的子网络。它通过不同窗口形状的卷积层和最大池化层来并行抽取信息,并使用1×11×1卷积层减少通道数从而降低模型复杂度。
GoogLeNet将多个设计精细的Inception块和其他层串联起来。其中Inception块的通道数分配之比是在ImageNet数据集上通过大量的实验得来的。
GoogLeNet和它的后继者们一度是ImageNet上最高效的模型之一:在类似的测试精度下,它们的计算复杂度往往更低。
"""
import sys
import torch
import torch.nn.functional as F
from torch import nn
sys.path.append("../../..")
from cvnet.dataset import fashion_mnist
from cvnet.engine import trainer
from cvnet.models.cls.custom_layer import FlattenLayer, GlobalAvgPool2d
class Inception(nn.Module):
def __init__(self, in_c, c1, c2, c3, c4):
# c1 - c4为每条线路里的层的输出通道数
super().__init__()
# route1, 1x1
self.p1_1 = nn.Conv2d(in_c, c1, kernel_size=1)
# route2, 1x1后接3x3卷积层
self.p2_1 = nn.Conv2d(in_c, c2[0], kernel_size=1)
self.p2_2 = nn.Conv2d(c2[0], c2[1], kernel_size=3, padding=1)
# route3, 1x1后接5x5卷积层
self.p3_1 = nn.Conv2d(in_c, c3[0], kernel_size=1)
self.p3_2 = nn.Conv2d(c3[0], c3[1], kernel_size=5, padding=2)
# route4, 3x3最大池化后接1x1
self.p4_1 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1)
self.p4_2 = nn.Conv2d(in_c, c4, kernel_size=1)
def forward(self, x):
p1 = F.relu(self.p1_1(x))
p2 = F.relu(self.p2_2(F.relu(self.p2_1(x))))
p3 = F.relu(self.p3_2(F.relu(self.p3_1(x))))
p4 = F.relu(self.p4_2(F.relu(self.p4_1(x))))
# 在通道维上连结输出
return torch.cat((p1, p2, p3, p4), dim=1)
# GoogLeNet跟VGG一样,在主体卷积部分中使用5个模块(block),每个模块之间使用步幅为2的3×3最大池化层来减小输出高宽。
# 第一模块使用一个64通道的7×7卷积层。
b1 = nn.Sequential(nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3),
nn.ReLU(),
nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
# 第二模块使用2个卷积层:首先是64通道的1×11×1卷积层,然后是将通道增大3倍的3×33×3卷积层。它对应Inception块中的第二条线路。
b2 = nn.Sequential(nn.Conv2d(64, 64, kernel_size=1),
nn.Conv2d(64, 192, kernel_size=3, padding=1),
nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
# 第三模块串联2个完整的Inception块。
b3 = nn.Sequential(Inception(192, 64, (96, 128), (16, 32), 32),
Inception(256, 128, (128, 192), (32, 96), 64),
nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
# 第四模块更加复杂。它串联了5个Inception块,
b4 = nn.Sequential(Inception(480, 192, (96, 208), (16, 48), 64),
Inception(512, 160, (112, 224), (24, 64), 64),
Inception(512, 128, (128, 256), (24, 64), 64),
Inception(512, 112, (144, 288), (32, 64), 64),
Inception(528, 256, (160, 320), (32, 128), 128),
nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
# 第五模块有输出通道数为256+320+128+128=832256+320+128+128=832和384+384+128+128=1024384+384+128+128=1024的两个Inception块。
b5 = nn.Sequential(Inception(832, 256, (160, 320), (32, 128), 128),
Inception(832, 384, (192, 384), (48, 128), 128),
GlobalAvgPool2d())
# 最后我们将输出变成二维数组后接上一个输出个数为标签类别数的全连接层。
net = nn.Sequential(
b1, b2, b3, b4, b5,
FlattenLayer(),
# 标签类别数是10
nn.Linear(1024, 10)
)
if __name__ == '__main__':
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(net)
print("-" * 42)
net = nn.Sequential(b1, b2, b3, b4, b5, FlattenLayer(), nn.Linear(1024, 10))
print(net)
X = torch.rand(1, 1, 96, 96)
for name, blk in net.named_children():
X = blk(X)
print(name, 'output shape:', X.shape)
batch_size = 128
# 如出现“out of memory”的报错信息,可减小batch_size或resize
train_iter, test_iter = fashion_mnist.load_data_fashion_mnist(batch_size, resize=96)
lr, num_epochs = 0.001, 5
optimizer = torch.optim.Adam(net.parameters(), lr=lr)
trainer.train(net, train_iter, test_iter, batch_size, optimizer, device, num_epochs)
|
from functools import update_wrapper
import os
import os.path
import shutil
import tempfile
import unittest # noqa
from docutils import nodes
from docutils.parsers.rst import directives
from docutils.parsers.rst import roles
from sphinx.application import Sphinx
# pylint:disable=no-self-use,protected-access,too-few-public-methods
# useless-object-inheritance is version specific
# pylint:disable=bad-option-value,useless-object-inheritance
# Trick to avoid unresonable truncation on assertEqual
# $ https://stackoverflow.com/a/61345284/99834
# if 'unittest.util' in __import__('sys').modules:
# # Show full diff in self.assertEqual.
# __import__('sys').modules[
# 'unittest.util'
# ]._MAX_LENGTH = 9999 # pylint: disable=protected-access
class Lazy(object):
def __init__(self, func, name=None):
if name is None:
name = func.__name__
self.data = (func, name)
update_wrapper(self, func)
def __get__(self, inst, class_):
if inst is None:
return self
func, name = self.data
value = func(inst)
inst.__dict__[name] = value
inst.addCleanup(delattr, inst, name)
return value
#: conf.py for tests
CONF_PY = """\
extensions = ['sphinxcontrib.programoutput']
source_suffix = '.rst'
master_doc = 'index'
project = u'epydoc-test'
copyright = u'2011, foo'
version = '1'
release = '1'
exclude_patterns = []
pygments_style = 'sphinx'
html_theme = 'default'
"""
def _find_duplicate_default_nodes():
from sphinx import addnodes # pylint:disable=import-outside-toplevel
class App(object):
def __init__(self):
self.nodes = set()
def add_node(self, node):
self.nodes.add(node.__name__)
app = App()
try:
addnodes.setup(app)
except AttributeError:
# Sphinx 1 doesn't have this
pass
return app.nodes
class AppMixin(object):
#: The contents of the main 'doc.rst' document.
#:
#: This will be written as a bytestring to the document, allowing for
#: the document to be in an arbitrary encoding.
#:
#: If this object is not a bytestring, it will first be encoded using
#: the encoding named in `self.document_encoding`.
document_content = '=============\ndummy content\n=============\n'
document_encoding = 'utf-8'
duplicate_nodes_to_remove = _find_duplicate_default_nodes()
def setUp(self):
# Avoid "WARNING: while setting up extension
# sphinxcontrib.programoutput: directive u'program-output' is
# already registered, it will be overridden".
# This may only be needed for Sphinx 1.
self.directives = directives._directives.copy()
# Likewise for 'eq'
self.roles = roles._roles.copy()
# Avoid error:
# node class 'toctree' is already registered, its visitors will be overridden
# By default this class has *no* `visit_` methods
for node in self.duplicate_nodes_to_remove:
if hasattr(nodes.GenericNodeVisitor, 'visit_' + node):
delattr(nodes.GenericNodeVisitor, 'visit_' + node)
def tearDown(self):
directives._directives = self.directives
roles._roles = self.roles
@Lazy
def tmpdir(self):
d = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, d)
return d
@Lazy
def srcdir(self):
"""
Generated source directory for test Sphinx application.
"""
tmpdir = self.tmpdir
srcdir = os.path.join(tmpdir, 'src')
os.mkdir(srcdir)
confpy = os.path.join(srcdir, 'conf.py')
with open(confpy, 'w') as f:
f.write(CONF_PY)
index_document = os.path.join(srcdir, 'index.rst')
with open(index_document, 'w') as f:
f.write(
"""\
.. toctree::
content/doc"""
)
content_directory = os.path.join(srcdir, 'content')
os.mkdir(content_directory)
content_document = os.path.join(content_directory, 'doc.rst')
contents = self.document_content
if not isinstance(contents, bytes):
contents = contents.encode(self.document_encoding)
with open(content_document, 'wb') as f:
f.write(b"=====\n")
f.write(b"Title\n")
f.write(b"=====\n\n")
f.write(contents)
return srcdir
@Lazy
def outdir(self):
return os.path.join(self.tmpdir, 'html')
@Lazy
def doctreedir(self):
return os.path.join(self.tmpdir, 'doctrees')
@Lazy
def confoverrides(self):
return {}
@Lazy
def app(self):
"""
Sphinx application for the current test.
"""
srcdir = self.srcdir
outdir = self.outdir
doctreedir = self.doctreedir
confoverrides = self.confoverrides
warningiserror = not self.ignore_warnings
app = Sphinx(
str(srcdir),
str(srcdir),
str(outdir),
str(doctreedir),
'html',
status=None,
warning=None,
freshenv=None,
warningiserror=warningiserror,
confoverrides=confoverrides,
)
if self.build_app:
app.build()
return app
@Lazy
def build_app(self): # pylint:disable=method-hidden
return False
@Lazy
def ignore_warnings(self):
return True
@Lazy
def doctree(self):
getattr(self, 'build_app')
self.build_app = True
app = self.app
return app.env.get_doctree('content/doc')
assert isinstance(AppMixin.app, Lazy) # coverage
|
<filename>src/fp16/fp16util.py
# coding=utf-8
# Copyright (c) 2020, Sber. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch
import torch.nn as nn
from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
from torch.autograd import Variable
from src import mpu
class tofp16(nn.Module):
"""
Utility module that implements::
def forward(self, input):
return input.half()
"""
def __init__(self):
super(tofp16, self).__init__()
def forward(self, input):
return input.half()
def BN_convert_float(module):
"""
Utility function for network_to_half().
Retained for legacy purposes.
"""
if isinstance(module, torch.nn.modules.batchnorm._BatchNorm) and module.affine is True:
module.float()
for child in module.children():
BN_convert_float(child)
return module
def network_to_half(network):
"""
Convert model to half precision in a batchnorm-safe way.
Retained for legacy purposes. It is recommended to use FP16Model.
"""
return nn.Sequential(tofp16(), BN_convert_float(network.half()))
def convert_module(module, dtype):
"""
Converts a module's immediate parameters and buffers to dtype.
"""
for param in module.parameters(recurse=False):
if param is not None:
if param.data.dtype.is_floating_point:
param.data = param.data.to(dtype=dtype)
if param._grad is not None and param._grad.data.dtype.is_floating_point:
param._grad.data = param._grad.data.to(dtype=dtype)
for buf in module.buffers(recurse=False):
if buf is not None and buf.data.dtype.is_floating_point:
buf.data = buf.data.to(dtype=dtype)
def convert_network(network, dtype):
"""
Converts a network's parameters and buffers to dtype.
"""
for module in network.modules():
if isinstance(module, torch.nn.modules.batchnorm._BatchNorm) and module.affine is True:
continue
convert_module(module, dtype)
return network
class FP16Model(nn.Module):
"""
Convert model to half precision in a batchnorm-safe way.
"""
def __init__(self, network):
super(FP16Model, self).__init__()
self.network = convert_network(network, dtype=torch.half)
def forward(self, *inputs):
inputs = tuple(t.half() for t in inputs)
return self.network(*inputs)
def backwards_debug_hook(grad):
raise RuntimeError("master_params recieved a gradient in the backward pass!")
def prep_param_lists(model, flat_master=False):
"""
Creates a list of FP32 master parameters for a given model, as in
`Training Neural Networks with Mixed Precision: Real Examples`_.
Args:
model (torch.nn.Module): Existing Pytorch model
flat_master (bool, optional, default=False): Flatten the master parameters into a single tensor, as a performance optimization.
Returns:
A tuple (``model_params``, ``master_params``). ``model_params`` is a list of the model's parameters for later use with :func:`model_grads_to_master_grads` and :func:`master_params_to_model_params`. ``master_params`` is a list of FP32 master gradients. If ``flat_master=True``, ``master_params`` will be a list with one element.
Example::
model_params, master_params = prep_param_lists(model)
.. warning::
Currently, if ``flat_master=True``, all the model's parameters must be the same type. If the model has parameters of different types, use ``flat_master=False``, or use :class:`FP16_Optimizer`.
.. _`Training Neural Networks with Mixed Precision: Real Examples`:
http://on-demand.gputechconf.com/gtc/2018/video/S81012/
"""
model_params = [param for param in model.parameters() if param.requires_grad]
if flat_master:
# Give the user some more useful error messages
try:
# flatten_dense_tensors returns a contiguous flat array.
# http://pytorch.org/docs/master/_modules/torch/_utils.html
master_params = _flatten_dense_tensors([param.data for param in model_params]).float()
except:
print("Error in prep_param_lists: model may contain a mixture of parameters "
"of different types. Use flat_master=False, or use F16_Optimizer.")
raise
master_params = torch.nn.Parameter(master_params)
master_params.requires_grad = True
# master_params.register_hook(backwards_debug_hook)
if master_params.grad is None:
master_params.grad = master_params.new(*master_params.size())
return model_params, [master_params]
else:
master_params = [param.clone().float().detach() for param in model_params]
for param in master_params:
param.requires_grad = True
return model_params, master_params
def model_grads_to_master_grads(model_params, master_params, flat_master=False):
"""
Copy model gradients to master gradients.
Args:
model_params: List of model parameters created by :func:`prep_param_lists`.
master_params: List of FP32 master parameters created by :func:`prep_param_lists`. If ``master_params`` was created with ``flat_master=True``, ``flat_master=True`` should also be supplied to :func:`model_grads_to_master_grads`.
"""
if flat_master:
# The flattening may incur one more deep copy than is necessary.
master_params[0].grad.data.copy_(
_flatten_dense_tensors([p.grad.data for p in model_params]))
else:
for model, master in zip(model_params, master_params):
if model.grad is not None:
if master.grad is None:
master.grad = Variable(master.data.new(*master.data.size()))
master.grad.data.copy_(model.grad.data)
else:
master.grad = None
def master_params_to_model_params(model_params, master_params, flat_master=False):
"""
Copy master parameters to model parameters.
Args:
model_params: List of model parameters created by :func:`prep_param_lists`.
master_params: List of FP32 master parameters created by :func:`prep_param_lists`. If ``master_params`` was created with ``flat_master=True``, ``flat_master=True`` should also be supplied to :func:`master_params_to_model_params`.
"""
if flat_master:
for model, master in zip(model_params,
_unflatten_dense_tensors(master_params[0].data, model_params)):
model.data.copy_(master)
else:
for model, master in zip(model_params, master_params):
model.data.copy_(master.data)
# Backward compatibility fixes
def to_python_float(t):
if hasattr(t, 'item'):
return t.item()
else:
return t[0]
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
clip_grad_norm = mpu.clip_grad_norm
# elif TORCH_MAJOR == 0 and TORCH_MINOR <= 4:
# clip_grad_norm = torch.nn.utils.clip_grad_norm
# else:
# clip_grad_norm = torch.nn.utils.clip_grad_norm_
|
#!/usr/bin/python3
#
import struct
import os
import sys
import math
def readshort():
return struct.unpack("<H", rom.read(2))[0]
def readbyte():
return struct.unpack("<B", rom.read(1))[0]
def abspointer(bank, offset):
return bank*0x4000+offset-0x4000
def readfarpointers(offset, amount=151):
rom.seek(offset)
pointers = []
for i in range(amount):
offset = readshort()
bank = readbyte()
assert 0x3fff < offset < 0x8000
pointers.append((offset - 0x4000) + 0x4000 * bank)
return pointers
def readtiles(amount):
tiles = []
tile = []
for i in range(amount*8*4):
high = readbyte()
low = readbyte()
#print(hex(i), hex(s), high, low)
for i in range(8)[::-1]:
h = (high >> i) & 0b1
l = (low >> i) & 0b1
pixel = (l*2+h)
tile.append(pixel)
if len(tile)==8*8:
tiles.append(tile)
tile = []
#print(len(tiles))
#raise
return tiles
def readcolor():
s = readshort()
blue = (s >> 10)
green = (s >> 5) % 32
red = (s) % 32
return (red, green, blue)
def readpalette():
pal = []
for i in range(4):
pal.append(readcolor())
return pal
def createppm(tiles, width=6, height=4):
ppm = """P6
{0} {1}
255
""".format(width*8, height*8).encode("ascii")
for row in range(height*8):
for col in range(width*8):
#print("{}x{} [{}][{}] - ".format(row,col, (width)*(row//8)+(col//8), 8*(row%8)+(col%8)), end="")
try:
r, g, b = tiles[(width)*(row//8)+(col//8)][8*(row%8)+(col%8)]
ppm += struct.pack("BBB", r*8, g*8, b*8)
except IndexError:
raise
return ppm
if len(sys.argv) != 2:
sys.exit('usage: python3 pinballsprites.py rom.gbc')
rom = open(sys.argv[1], 'rb')
sprite_pointers = readfarpointers(0x12b50)
palette_pointers = readfarpointers(0x12eda)
palette_map_pointers = readfarpointers(0x12d15)
pokesprites = []
for pointer in sprite_pointers:
rom.seek(pointer)
pokesprites.append(readtiles(6*4))
print("read {}".format(hex(pointer)))
pokesilhouettes = []
for pointer in sprite_pointers:
rom.seek(pointer+6*4*8*2)
pokesilhouettes.append(readtiles(6*4))
print("read silhouette {}".format(hex(pointer)))
pokepalettes = []
for pointer in palette_pointers:
rom.seek(pointer)
pokepalettes.append((readpalette(), readpalette()))
pokepalette_maps = []
for pointer in palette_map_pointers:
rom.seek(pointer)
palmap = []
for i in range(6*4):
palmap.append(readbyte())
pokepalette_maps.append(palmap)
for sprite, palettes, palmap in zip(pokesprites, pokepalettes, pokepalette_maps):
for tile, pal in zip(sprite, palmap):
#print(pal, hex(len(sprite)), hex(len(palmap)), hex(6*4))
palette = palettes[pal-6]
for i, pixel in enumerate(tile):
tile[i] = palette[pixel]
silhouettepalette = ((31, 31, 31), (20, 20, 20), (8, 8, 8), (0, 0, 0))
for sprite in pokesilhouettes:
for tile in sprite:
for i, pixel in enumerate(tile):
tile[i] = silhouettepalette[pixel]
#height = (math.ceil(len(tiles)/16))*8
for i in range(len(pokesprites)):
sprite = pokesprites[i]
ppm = createppm(sprite)
g = open('s/{}.ppm'.format(i+1), 'wb')
g.write(ppm)
g.close()
silhouette = pokesilhouettes[i]
ppm = createppm(pokesilhouettes[i])
g = open('s/silhouettes/{}.ppm'.format(i+1), 'wb')
g.write(ppm)
g.close()
print ('Wrote {}'.format(i))
|
from asyncio.log import logger
from unittest import result
import eventlet
from numpy import broadcast
# from https://github.com/eventlet/eventlet/issues/670
eventlet.monkey_patch(select=False)
import sys
from flask import (
Flask,
request,
render_template,
session,
send_file,
send_from_directory,
make_response,
)
from flask_cors import CORS
from flask_socketio import SocketIO
from flask_socketio import emit
from flask_caching import Cache
import secrets
import time
import os
import io
import uuid
import argparse
import functools
from argparse import RawTextHelpFormatter
from datetime import datetime
from datetime import timedelta
import json
from json import JSONDecodeError
from pathlib import Path
import rdflib
from rdflib import ConjunctiveGraph, URIRef
import extruct
import logging
from rich.console import Console
from rich.table import Table
from rich.text import Text
from rich.progress import track
import metrics.util as util
import metrics.statistics as stats
from metrics import test_metric
from metrics.FAIRMetricsFactory import FAIRMetricsFactory
from metrics.WebResource import WebResource
from metrics.Evaluation import Result
from profiles.bioschemas_shape_gen import validate_any_from_KG
from profiles.bioschemas_shape_gen import validate_any_from_microdata
import git
app = Flask(__name__)
app.logger.setLevel(logging.DEBUG)
CORS(app)
app.config["CORS_HEADERS"] = "Content-Type"
if app.config["ENV"] == "production":
app.config.from_object("config.ProductionConfig")
else:
app.config.from_object("config.DevelopmentConfig")
print(f'ENV is set to: {app.config["ENV"]}')
cache = Cache(app)
socketio = SocketIO(app)
socketio.init_app(app, cors_allowed_origins="*", async_mode="eventlet")
app.secret_key = secrets.token_urlsafe(16)
sample_resources = {
"Examples": [
{
"text": "Dataset Dataverse",
"url": "https://data.inrae.fr/dataset.xhtml?persistentId=doi:10.15454/P27LDX",
},
{
"text": "Workflow",
"url": "https://workflowhub.eu/workflows/18", # Workflow in WorkflowHub
},
{
"text": "Publication Datacite",
"url": "https://search.datacite.org/works/10.7892/boris.108387", # Publication in Datacite
},
{
"text": "Dataset",
"url": "https://doi.pangaea.de/10.1594/PANGAEA.914331", # dataset in PANGAEA
},
{
"text": "Tool",
"url": "https://bio.tools/jaspar",
},
],
}
metrics = [
{"name": "f1", "category": "F", "description": "F1 verifies that ... "},
{"name": "f2", "category": "F", "description": "F2 verifies that ... "},
{"name": "f3", "category": "F", "description": "F3 verifies that ... "},
{"name": "a1", "category": "A"},
{"name": "a2", "category": "A"},
]
METRICS = {}
# json_metrics = test_metric.getMetrics()
factory = FAIRMetricsFactory()
#
# # for i in range(1,3):
# try:
# # metrics.append(factory.get_metric("test_f1"))
# # metrics.append(factory.get_metric("test_r2"))
# for metric in json_metrics:
# # remove "FAIR Metrics Gen2" from metric name
# name = metric["name"].replace("FAIR Metrics Gen2- ", "")
# # same but other syntax because of typo
# name = name.replace("FAIR Metrics Gen2 - ", "")
# principle = metric["principle"]
# METRICS[name] = factory.get_metric(
# name,
# metric["@id"],
# metric["description"],
# metric["smarturl"],
# principle,
# metric["creator"],
# metric["created_at"],
# metric["updated_at"],
# )
# except ValueError as e:
# print(f"no metrics implemention for {e}")
#
# # A DEPLACER AU LANCEMENT DU SERVEUR ######
# METRICS_RES = test_metric.getMetrics()
METRICS_CUSTOM = factory.get_FC_metrics()
for i, key in enumerate(METRICS_CUSTOM):
METRICS_CUSTOM[key].set_id("FC_" + str(i))
KGS = {}
RDF_TYPE = {}
FILE_UUID = ""
DICT_TEMP_RES = {}
@app.context_processor
def inject_app_version():
repo = git.Repo(".")
tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
latest_tag = tags[-1]
return dict(version_tag=latest_tag)
@app.context_processor
def inject_jsonld():
return dict(jld=buildJSONLD())
@app.route("/favicon.ico")
def favicon():
return send_from_directory(
os.path.join(app.root_path, "static"),
"favicon.ico",
mimetype="image/vnd.microsoft.icon",
)
@app.route("/")
def home():
return render_template(
"index.html",
title="FAIR-Checker",
subtitle="Improve the FAIRness of your web resources",
)
@app.route("/")
def index():
return render_template(
"index.html",
)
@app.route("/about")
def about():
return render_template(
"about.html",
title="About",
subtitle="More about FAIR-Checker",
)
@app.route("/statistics")
def statistics():
return render_template(
"statistics.html",
title="Statistics",
subtitle="Visualize usage statistics of FAIR-Checker",
evals=stats.evaluations_this_week(),
success=stats.success_this_week(),
success_weekly=stats.success_weekly_one_year(),
failures=stats.failures_this_week(),
failures_weekly=stats.failures_weekly_one_year(),
f_success_weekly=stats.weekly_named_metrics(prefix="F", success=1),
f_failures_weekly=stats.weekly_named_metrics(prefix="F", success=0),
a_success_weekly=stats.weekly_named_metrics(prefix="A", success=1),
a_failures_weekly=stats.weekly_named_metrics(prefix="A", success=0),
i_success_weekly=stats.weekly_named_metrics(prefix="I", success=1),
i_failures_weekly=stats.weekly_named_metrics(prefix="I", success=0),
r_success_weekly=stats.weekly_named_metrics(prefix="R", success=1),
r_failures_weekly=stats.weekly_named_metrics(prefix="R", success=0),
f_success=stats.this_week_for_named_metrics(prefix="F", success=1),
f_failures=stats.this_week_for_named_metrics(prefix="F", success=0),
a_success=stats.this_week_for_named_metrics(prefix="A", success=1),
a_failures=stats.this_week_for_named_metrics(prefix="A", success=0),
i_success=stats.this_week_for_named_metrics(prefix="I", success=1),
i_failures=stats.this_week_for_named_metrics(prefix="I", success=0),
r_success=stats.this_week_for_named_metrics(prefix="R", success=1),
r_failures=stats.this_week_for_named_metrics(prefix="R", success=0),
)
@socketio.on("webresource")
def handle_webresource(url):
print("A new url to retrieve metadata from !")
@socketio.on("evaluate_metric")
def handle_metric(json):
"""
socketio Handler for a metric calculation requests, calling FAIRMetrics API.
emit the result of the test
@param json dict Contains the necessary informations to execute evaluate a metric.
"""
implem = json["implem"]
metric_name = json["metric_name"]
client_metric_id = json["id"]
url = json["url"]
print("Testing: " + url)
# if implem == "FAIRMetrics":
# evaluate_fairmetrics(json, metric_name, client_metric_id, url)
if implem == "FAIR-Checker":
evaluate_fc_metrics(metric_name, client_metric_id, url)
else:
print("Invalid implem")
logging.warning("Invalid implem")
def evaluate_fairmetrics(json, metric_name, client_metric_id, url):
id = METRICS[metric_name].get_id()
api_url = METRICS[metric_name].get_api()
principle = METRICS[metric_name].get_principle()
print("RUNNING " + principle + " for " + str(url))
emit("running_f")
try:
result_object = METRICS[metric_name].evaluate(url)
except JSONDecodeError:
print("Error json")
print("error_" + client_metric_id)
# emit_json = {
# "score": -1,
# "comment": "None",
# "time": str(evaluation_time),
# "name": "",
# "csv_line": "\t\t\t"
# }
emit("error_" + client_metric_id)
return False
# Eval time removing microseconds
evaluation_time = result_object.get_test_time() - timedelta(
microseconds=result_object.get_test_time().microseconds
)
score = result_object.get_score()
comment = result_object.get_reason()
###
content_uuid = json["uuid"]
# remove empty lines from the comment
comment = test_metric.cleanComment(comment)
# all_comment = comment
# select only success and failure
comment = test_metric.filterComment(comment, "sf")
# json_result = {
# "url": url,
# "api_url": api_url,
# "principle": principle,
# "id": id,
# "score": score,
# "exec_time": str(evaluation_time),
# "date": str(datetime.now().isoformat()),
# }
# print(json_result)
# might be removed
write_temp_metric_res_file(
principle, api_url, evaluation_time, score, comment, content_uuid
)
principle = principle.split("/")[-1]
metric_label = api_url.split("/")[-1].replace("gen2_", "")
name = principle + "_" + metric_label
csv_line = '"{}"\t"{}"\t"{}"\t"{}"'.format(
name, score, str(evaluation_time), comment
)
# print(name)
emit_json = {
"score": score,
"comment": comment,
"time": str(evaluation_time),
"name": name,
"csv_line": csv_line,
}
recommendation(emit_json, metric_name, comment)
# print(emit_json)
emit("done_" + client_metric_id, emit_json)
print("DONE " + principle)
def evaluate_fc_metrics(metric_name, client_metric_id, url):
# print("OK FC Metrics")
# print(cache.get("TOTO"))
# print(METRICS_CUSTOM)
logging.warning("Evaluating FAIR-Checker metric")
id = METRICS_CUSTOM[metric_name].get_id()
print("ID: " + id)
print("Client ID: " + client_metric_id)
# Faire une fonction recursive ?
if cache.get(url) == "pulling":
while True:
time.sleep(2)
if not cache.get(url) == "pulling":
webresource = cache.get(url)
break
elif not isinstance(cache.get(url), WebResource):
cache.set(url, "pulling")
webresource = WebResource(url)
cache.set(url, webresource)
elif isinstance(cache.get(url), WebResource):
webresource = cache.get(url)
METRICS_CUSTOM[metric_name].set_web_resource(webresource)
name = METRICS_CUSTOM[metric_name].get_principle_tag()
print("Evaluating: " + metric_name)
result = METRICS_CUSTOM[metric_name].evaluate()
score = result.get_score()
# Eval time removing microseconds
evaluation_time = result.get_test_time() - timedelta(
microseconds=result.get_test_time().microseconds
)
# comment = result.get_reason()
comment = result.get_log_html()
recommendation = result.get_recommendation()
print(recommendation)
# Persist Evaluation oject in MongoDB
implem = METRICS_CUSTOM[metric_name].get_implem()
id = METRICS_CUSTOM[metric_name].get_id()
# result.set_metrics(name)
# result.set_implem(implem)
result.persist()
# result.close_log_stream()
csv_line = '"{}"\t"{}"\t"{}"\t"{}"\t"{}"'.format(
id, name, score, str(evaluation_time), comment
)
csv_line = {
"id": id,
"name": name,
"score": score,
"time": str(evaluation_time),
"comment": comment,
}
emit_json = {
"score": str(score),
"time": str(evaluation_time),
"comment": comment,
"recommendation": recommendation,
"csv_line": csv_line,
# "name": name,
}
emit("done_" + client_metric_id, emit_json)
print("DONE our own metric !")
@socketio.on("quick_structured_data_search")
def handle_quick_structured_data_search(url):
if url == "":
return False
extruct_rdf = util.extract_rdf_from_html(url)
graph = util.extruct_to_rdf(extruct_rdf)
result_list = util.rdf_to_triple_list(graph)
emit("done_data_search", result_list)
def recommendation(emit_json, metric_name, comment):
recommendation_dict = {
# F1
"unique_identifier": {
"did not match any known identification system (tested inchi, doi, "
"handle, uri) and therefore did not pass this metric. If you think"
" this is an error, please contact the FAIR Metrics group "
"(http://fairmetrics.org).": "You may use another identification "
"scheme for your resource. For instance, provide a DOI, a URI "
"(https://www.w3.org/wiki/URI) or a pubmed id (PMID) for an academic"
"paper. Also, look at the FAIR Cookbook: "
"https://fairplus.github.io/the-fair-cookbook/content/recipes/findability/identifiers.html",
},
"data_identifier_persistence": {
"FAILURE: The identifier": "You may use another identification scheme for your resource. For instance, provide a DOI, a URI (https://www.w3.org/wiki/URI) or a pubmed id for an academic paper.",
"FAILURE: Was unable to locate the data identifier in the metadata using any (common) property/predicate reserved": "Ensure that the resource identifier is part of your web page meta-data (RDFa, embedded JSON-LD, microdata, etc.)",
"FAILURE: The GUID identifier of the data": "Ensure that the resource identifier, part of your web page meta-data (RDFa, embedded JSON-LD, microdata, etc.) is well formed (DOI, URI, PMID, etc.). ",
"FAILURE: The GUID does not conform with any known permanent-URL system.": "Ensure that the used identification scheme is permanent. For instance DOIs or PURLs are sustainable over the long term.",
},
"identifier_persistence": {
"The GUID identifier of the metadata": "Ensure that meta-data describing your resource use permanent and well fprmed identifiers (PURLs, DOIs, etc.)",
"FAILURE: The metadata GUID does not conform with any known permanent-URL system.": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
},
# F2
"grounded_metadata": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: no linked-data style structured metadata found.": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
},
"structured_metadata": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: no structured metadata found": "Ensure that meta-data describing your resource use a machine readable format such as JSON or RDF.",
},
# F3
"data_identifier_explicitly_in_metadata": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: Was unable to locate the data identifier in the metadata using any (common) property/predicate reserved": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
},
"metadata_identifier_explicitly_in_metadata": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: No metadata identifiers were found in the metadata record": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: No metadata identifiers were found in the metadata record using predicates": "Ensure that identifiers in your metadata are linked together through typical RDF properties such as (schema:mainEntity, dcterms:identifier, etc.)",
"FAILURE: linked data metadata was not found, so its identifier could not be located": "Ensure that meta-data describing your resource use the RDF machine readable standard.",
"FAILURE: While (apparent) metadata record identifiers were found": "Ensure that the resource identifier is explicitely referred to in your meta-data. ",
},
# F4
"searchable_in_major_search_engine": {
"FAILURE: The identifier": "Ensure that the resource identifier, part of your web page meta-data (RDFa, embedded JSON-LD, microdata, etc.) is well formed (DOI, URI, PMID, etc.). Also, see the corresponding FAIR Cookbook page: https://fairplus.github.io/the-fair-cookbook/content/recipes/findability/seo.html",
"FAILURE: NO ACCESS KEY CONFIGURED FOR BING. This test will now abort with failure": "No recommendation, server side issue",
"FAILURE: Was unable to discover the metadata record by search in Bing using any method": "Ensure that meta-data describing your resource use the machine readable standards parsed by major search engines such as schema.org OpenGraph, etc. Also, see the corresponding FAIR Cookbook page: https://fairplus.github.io/the-fair-cookbook/content/recipes/findability/seo.html",
},
# A1.1
"uses_open_free_protocol_for_metadata_retrieval": {
"FAILURE: The identifier ": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
},
"uses_open_free_protocol_for_data_retrieval": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: Was unable to locate the data identifier in the metadata using any (common) property/predicate reserved for this purpose": "Ensure that identifiers in your metadata are linked together through typical RDF properties such as (schema:mainEntity, dcterms:identifier, etc.)",
},
# A1.2
"data_authentication_and_authorization": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: No data identifier was found in the metadata record": "Ensure that identifiers in your metadata are linked together through typical RDF properties such as (schema:mainEntity, dcterms:identifier, etc.)",
},
"metadata_authentication_and_authorization": {
"FAILURE: The GUID identifier of the metadata": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
},
# A2
"metadata_persistence": {
"FAILURE: The GUID identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: http://www.w3.org/2000/10/swap/pim/doc#persistencePolicy states that the range of the property must be a resource.": "Ensure that a peristence policy predicate is used in the resource metadata : http://www.w3.org/2000/10/swap/pim/doc#persistencePolicy ",
"FAILURE: Persistence policy did not resolve": "Ensure that a peristence policy predicate is used in the resource metadata : http://www.w3.org/2000/10/swap/pim/doc#persistencePolicy ",
"FAILURE: was unable to find a persistence policy using any approach": "Ensure that a peristence policy predicate is used in the resource metadata : http://www.w3.org/2000/10/swap/pim/doc#persistencePolicy ",
},
# I1
"data_knowledge_representation_language_weak": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: the data could not be found, or does not appear to be in a recognized knowledge representation language": "Ensure that metadata leverage a standard knowledge representation language such as RDFS, SKOS, OWL, OBO, etc.",
"FAILURE: The reported content-type header": "Ensure that your resource is accessible by an HTTP GET query and provides a content-type header. You may ask to your resource publisher. ",
"which is not a known Linked Data format": "Ensure that your resource is web accessible and that the HTTP message provides a linked data content-type, e.g. application/ld+json or text/turtle",
"which is not likely to contain structured data": "Ensure that your resource is web accessible and that the HTTP message provides a structured data content-type, e.g. application/json. You may ask your resource publisher.",
"FAILURE: The URL to the data is not reporting a Content-Type in its headers. This test will now halt": "Ensure that your resource is accessible by an HTTP GET query and provides a content-type header. You may ask to your resource publisher.",
"failed to resolve via a HEAD call with headers": "Ensure that your resource is accessible by an HTTP GET query and provides a content-type header. You may ask to your resource publisher.",
},
"data_knowledge_representation_language_strong": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: the data could not be found, or does not appear to be in a recognized knowledge representation language": "Ensure that metadata leverage a standard knowledge representation language such as RDFS, SKOS, OWL, OBO, etc.",
"FAILURE: The reported content-type header": "Ensure that your resource is accessible by an HTTP GET query and provides a content-type header. You may ask to your resource publisher. ",
"which is not a known Linked Data format": "Ensure that your resource is web accessible and that the HTTP message provides a linked data content-type, e.g. application/ld+json or text/turtle",
"which is not likely to contain structured data": "Ensure that your resource is web accessible and that the HTTP message provides a structured data content-type, e.g. application/json. You may ask your resource publisher.",
"FAILURE: The URL to the data is not reporting a Content-Type in its headers. This test will now halt": "Ensure that your resource is accessible by an HTTP GET query and provides a content-type header. You may ask to your resource publisher.",
"failed to resolve via a HEAD call with headers": "Ensure that your resource is accessible by an HTTP GET query and provides a content-type header. You may ask to your resource publisher.",
},
"metadata_knowledge_representation_language_weak": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: unable to find any kind of structured metadata": "Ensure that meta-data describing your resource use the RDF machine readable standard. Also, you can check the Interoperability recipes of the FAIR Cookbook: https://fairplus.github.io/the-fair-cookbook/content/recipes/interoperability.html",
},
"metadata_knowledge_representation_language_strong": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: unable to find any kind of structured metadata": "Ensure that meta-data describing your resource use the RDF machine readable standard. Also, you can check the Interoperability recipes of the FAIR Cookbook: https://fairplus.github.io/the-fair-cookbook/content/recipes/interoperability.html",
},
# I2
"metadata_uses_fair_vocabularies_weak": {
"FAILURE: The identifier": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: No linked data metadata was found. Test is exiting": "Ensure that meta-data describing your resource use a machine readable format such as JSON or RDF.",
"FAILURE: No predicates were found that resolved to Linked Data": "Ensure that meta-data describing your resource use a machine readable format such as JSON or RDF.",
"The minimum to pass this test is 2/3 (with a minimum of 3 predicates in total)": "Ensure that in your metatdata, at least 2/3rd of your properties should leverage already known voabulary or ontology as registered in OLS, BioPortal, FAIRSharing regitries for instance. Also, check the FAIR Cookbook recipe about ontologies: https://fairplus.github.io/the-fair-cookbook/content/recipes/interoperability/introduction-terminologies-ontologies.html",
},
"metadata_uses_fair_vocabularies_strong": {
"FAILURE: The identifier ": "Ensure that meta-data describing your resource use permanent and well formed identifiers (PURLs, DOIs, etc.)",
"FAILURE: No linked data metadata was found. Test is exiting": "Ensure that meta-data describing your resource use a machine readable format such as JSON or RDF.",
"FAILURE: No predicates were found that resolved to Linked Data.": "Ensure that meta-data describing your resource use a machine readable format such as JSON or RDF.",
"The minimum to pass this test is 2/3 (with a minimum of 3 predicates in total)": "Ensure that in your metatdata, at least 2/3rd of your properties should leverage already known voabulary or ontology as registered in OLS, BioPortal, FAIRSharing regitries for instance. Also, check the FAIR Cookbook recipe about ontologies: https://fairplus.github.io/the-fair-cookbook/content/recipes/interoperability/introduction-terminologies-ontologies.html",
},
# I3
"metadata_contains_qualified_outward_references": {
"FAILURE: The identifier ": "You may use another identification scheme for your resource. For instance, provide a DOI, a URI (https://www.w3.org/wiki/URI) or a pubmed id (PMID) for an academic paper.",
"FAILURE: No linked data was found. Test is exiting.": "Ensure that your metadata is structured in RDF graphs.",
"triples discovered in the linked metadata pointed to resources hosted elsewhere. The minimum to pass this test is 1": "Ensure that your metadata use at least one identifier which is defined in an external resource (e.g. use a UniProt ID in your metadata, the uniprot id being described in UniProt KB)",
},
# R1.1
"metadata_includes_license_weak": {
"FAILURE: The identifier ": "You may use another identification scheme for your resource. For instance, provide a DOI, a URI (https://www.w3.org/wiki/URI) or a pubmed id (PMID) for an academic paper. Also, you can check the FAIR Cookbook recipe about Licensing: https://fairplus.github.io/the-fair-cookbook/content/recipes/reusability/ATI-licensing.html",
"FAILURE: No License property was found in the metadata.": "Ensure that a property defining the license of your resoure ispart of your metadata. For instance you can use dcterms:license or schema:license. Also, you can check the FAIR Cookbook recipe about Licensing: https://fairplus.github.io/the-fair-cookbook/content/recipes/reusability/ATI-licensing.html",
},
"metadata_includes_license_strong": {
"FAILURE: The identifier ": "You may use another identification scheme for your resource. For instance, provide a DOI, a URI (https://www.w3.org/wiki/URI) or a pubmed id (PMID) for an academic paper. Also, you can check the FAIR Cookbook recipe about Licensing: https://fairplus.github.io/the-fair-cookbook/content/recipes/reusability/ATI-licensing.html",
"FAILURE: No License property was found in the metadata.": "Ensure that a property defining the license of your resoure ispart of your metadata. For instance you can use dcterms:license or schema:license. Also, you can check the FAIR Cookbook recipe about Licensing: https://fairplus.github.io/the-fair-cookbook/content/recipes/reusability/ATI-licensing.html",
},
}
# recommendation
metric_name_key = metric_name.replace(" ", "_").replace("(", "").replace(")", "")
metric_name_key = metric_name_key.lower()
# print(metric_name_key)
# print(recommendation_dict.keys())
if metric_name_key in recommendation_dict.keys():
metric_failures = recommendation_dict[metric_name_key]
for key in metric_failures.keys():
# print(key)
# print(comment)
if key in comment:
print("found a match!")
emit_json["recommendation"] = metric_failures[key]
else:
print("no match")
else:
emit_json["recommendation"] = "Recommendation will be available soon."
def write_temp_metric_res_file(principle, api_url, time, score, comment, content_uuid):
global DICT_TEMP_RES
sid = request.sid
temp_file_path = "./temp/" + sid
principle = principle.split("/")[-1]
api_url = api_url.split("/")[-1].lstrip("gen2_")
name = principle + "_" + api_url
# print(name)
line = '"{}"\t"{}"\t"{}"\t"{}"\n'.format(name, score, str(time), comment)
# write csv file
if os.path.exists(temp_file_path):
with open(temp_file_path, "a") as fp:
fp.write(line)
print("success written")
if content_uuid in DICT_TEMP_RES.keys():
DICT_TEMP_RES[content_uuid] += line
else:
DICT_TEMP_RES[content_uuid] = line
@socketio.on("download_csv")
def handle_csv_download():
# temp_file_path = "./temp/" + FILE_UUID
print("Received download request from " + FILE_UUID)
# csv_download(temp_file_path)
@app.route("/base_metrics/csv-download/<uuid>")
def csv_download(uuid):
print("downloading !")
print(uuid)
output = io.StringIO()
output.write(DICT_TEMP_RES[uuid])
# write file object in BytesIO from StringIO
content = output.getvalue().encode("utf-8")
mem = io.BytesIO()
mem.write(content)
mem.seek(0)
print(json.dumps(DICT_TEMP_RES, sort_keys=True, indent=4))
try:
return send_file(
mem,
as_attachment=True,
attachment_filename="results.csv",
mimetype="text/csv",
cache_timeout=-1,
)
# return send_from_directory(
# "./temp/" + sid,
# as_attachment=True,
# attachment_filename='metrics_results.csv',
# mimetype='text/csv'
# )
except Exception as e:
return str(e)
# # not working
# @socketio.on("connected")
# def handle_connected(json):
# print(request.namespace.socket.sessid)
# print(request.namespace)
@socketio.on("connect")
def handle_connect():
global FILE_UUID
print("The random id using uuid() is : ", end="")
FILE_UUID = str(uuid.uuid1())
print(FILE_UUID)
print(request)
sid = request.sid
print("Connected with SID " + sid)
# Creates a new temp file
# with open("./temp/" + sid, 'w') as fp:
# pass
@socketio.on("disconnect")
def handle_disconnected():
print("Disconnected")
sid = request.sid
time.sleep(5)
print("Cleaning temp file after disconnect: " + sid)
if os.path.exists("./temp/" + sid):
os.remove("./temp/" + sid)
#######################################
#######################################
@socketio.on("get_latest_triples")
def handle_get_latest_triples():
sid = request.sid
kg = KGS[sid]
list_triples = []
for s, p, o in kg.triples((None, None, None)):
triple = {"subject": s, "predicate": p, "object": o}
list_triples.append(triple)
emit("send_triples", {"triples": list_triples})
@socketio.on("change_rdf_type")
def handle_change_rdf_type(data):
sid = request.sid
RDF_TYPE[sid] = data["rdf_type"]
kg = KGS[sid]
nb_triples = len(kg)
emit(
"send_annot_2",
{
"kg": str(kg.serialize(format=RDF_TYPE[sid])),
"nb_triples": nb_triples,
},
)
@socketio.on("retrieve_embedded_annot_2")
def handle_embedded_annot_2(data):
"""
socketio Handler to aggregate original page metadata with sparql endpoints.
emit the result of sparql requests
@param data dict Contains the data needed to aggregate (url, etc).
"""
# step = 0
print("handle annot_2")
sid = request.sid
print(sid)
RDF_TYPE[sid] = "turtle"
uri = str(data["url"])
print("retrieving embedded annotations for " + uri)
print("Retrieve KG for uri: " + uri)
web_resource = WebResource(uri)
kg = web_resource.get_rdf()
nb_triples = len(kg)
print(nb_triples)
KGS[sid] = kg
emit(
"send_annot_2",
{
"kg": str(kg.serialize(format=RDF_TYPE[sid])),
"nb_triples": nb_triples,
},
)
@socketio.on("update_annot_bioschemas")
def handle_annotationn(data):
new_kg = rdflib.ConjunctiveGraph()
new_kg.namespace_manager.bind("sc", URIRef("http://schema.org/"))
new_kg.namespace_manager.bind("bsc", URIRef("https://bioschemas.org/"))
new_kg.namespace_manager.bind("dct", URIRef("http://purl.org/dc/terms/"))
# TODO check that url is well formed
if util.is_URL(data["url"]):
uri = rdflib.URIRef(data["url"])
for p in data["warn"].keys():
if data["warn"][p]:
value = data["warn"][p]
if util.is_URL(value):
new_kg.add((uri, rdflib.URIRef(p), rdflib.URIRef(value)))
else:
new_kg.add((uri, rdflib.URIRef(p), rdflib.Literal(value)))
for p in data["err"].keys():
if data["err"][p]:
value = data["err"][p]
if util.is_URL(value):
new_kg.add((uri, rdflib.URIRef(p), rdflib.URIRef(value)))
else:
new_kg.add((uri, rdflib.URIRef(p), rdflib.Literal(value)))
# print("****** Turtle syntax *****")
# print(new_kg.serialize(format='turtle').decode())
# print("**************************")
print("***** JSON-LD syntax *****")
print()
print("**************************")
emit("send_bs_annot", str(new_kg.serialize(format="json-ld")))
@socketio.on("describe_opencitation")
def handle_describe_opencitation(data):
print("describing opencitation")
sid = request.sid
kg = KGS[sid]
uri = str(data["url"])
graph = str(data["graph"])
# kg = ConjunctiveGraph()
# kg.parse(data=graph, format="turtle")
# check if id or doi in uri
if util.is_DOI(uri):
uri = util.get_DOI(uri)
print(f"FOUND DOI: {uri}")
kg = util.describe_opencitation(uri, kg)
nb_triples = len(kg)
emit(
"send_annot_2",
{
"kg": str(kg.serialize(format=RDF_TYPE[sid])),
"nb_triples": nb_triples,
},
)
@socketio.on("describe_wikidata")
def handle_describe_wikidata(data):
print("describing wikidata")
sid = request.sid
kg = KGS[sid]
uri = str(data["url"])
graph = str(data["graph"])
# kg = ConjunctiveGraph()
# kg.parse(data=graph, format="turtle")
# check if id or doi in uri
if util.is_DOI(uri):
uri = util.get_DOI(uri)
print(f"FOUND DOI: {uri}")
kg = util.describe_wikidata(uri, kg)
nb_triples = len(kg)
emit(
"send_annot_2",
{
"kg": str(kg.serialize(format=RDF_TYPE[sid])),
"nb_triples": nb_triples,
},
)
@socketio.on("describe_loa")
def handle_describe_loa(data):
print("describing loa")
sid = request.sid
kg = KGS[sid]
uri = str(data["url"])
graph = str(data["graph"])
# kg = ConjunctiveGraph()
# kg.parse(data=graph, format="turtle")
# check if id or doi in uri
if util.is_DOI(uri):
uri = util.get_DOI(uri)
print(f"FOUND DOI: {uri}")
kg = util.describe_openaire(uri, kg)
nb_triples = len(kg)
emit(
"send_annot_2",
{
"kg": str(kg.serialize(format=RDF_TYPE[sid])),
"nb_triples": nb_triples,
},
)
@DeprecationWarning
@socketio.on("retrieve_embedded_annot")
def handle_embedded_annot(data):
"""
socketio Handler to aggregate original page metadata with sparql endpoints.
emit the result of sparql requests
@param data dict Contains the data needed to aggregate (url, etc).
"""
step = 0
sid = request.sid
print(sid)
uri = str(data["url"])
print("retrieving embedded annotations for " + uri)
print("Retrieve KG for uri: " + uri)
# page = requests.get(uri)
# html = page.content
# use selenium to retrieve Javascript genereted content
html = util.get_html_selenium(uri)
d = extruct.extract(
html, syntaxes=["microdata", "rdfa", "json-ld"], errors="ignore"
)
kg = ConjunctiveGraph()
# kg = util.get_rdf_selenium(uri, kg)
# kg = util.extruct_to_rdf(d)
base_path = Path(__file__).parent ## current directory
static_file_path = str((base_path / "static/data/jsonldcontext.json").resolve())
# remove whitespaces from @id values after axtruct
for key, val in d.items():
for dict in d[key]:
list(util.replace_value_char_for_key("@id", dict, " ", "_"))
for md in d["json-ld"]:
if "@context" in md.keys():
if ("https://schema.org" in md["@context"]) or (
"http://schema.org" in md["@context"]
):
md["@context"] = static_file_path
kg.parse(data=json.dumps(md, ensure_ascii=False), format="json-ld")
for md in d["rdfa"]:
if "@context" in md.keys():
if ("https://schema.org" in md["@context"]) or (
"http://schema.org" in md["@context"]
):
md["@context"] = static_file_path
kg.parse(data=json.dumps(md, ensure_ascii=False), format="json-ld")
for md in d["microdata"]:
if "@context" in md.keys():
if ("https://schema.org" in md["@context"]) or (
"http://schema.org" in md["@context"]
):
md["@context"] = static_file_path
kg.parse(data=json.dumps(md, ensure_ascii=False), format="json-ld")
KGS[sid] = kg
step += 1
emit("update_annot", step)
emit("send_annot", str(kg.serialize(format="turtle").decode()))
print(len(kg))
# check if id or doi in uri
if util.is_DOI(uri):
uri = util.get_DOI(uri)
print(f"FOUND DOI: {uri}")
# describe on lod.openair
# @TODO fix wikidata / LOA / etc. access
kg = util.describe_openaire(uri, kg)
step += 1
emit("update_annot", step)
emit("send_annot", str(kg.serialize(format="turtle").decode()))
print(len(kg))
# kg = util.describe_opencitation(uri, kg)
# step += 1
# emit('update_annot', step)
# emit('send_annot', str(kg.serialize(format='turtle').decode()))
# print(len(kg))
#
# kg = util.describe_wikidata(uri, kg)
# step += 1
# emit('update_annot', step)
# emit('send_annot', str(kg.serialize(format='turtle').decode()))
# print(len(kg))
kg = util.describe_biotools(uri, kg)
step += 1
emit("update_annot", step)
emit("send_annot", str(kg.serialize(format="turtle").decode()))
print(f"ended with step {step}")
print(len(kg))
print(step)
@socketio.on("complete_kg")
def handle_complete_kg(json):
print("completing KG for " + str(json["url"]))
@socketio.on("check_kg")
def check_kg(data):
step = 0
sid = request.sid
print(sid)
uri = str(data["url"])
if not sid in KGS.keys():
handle_embedded_annot(data)
elif not KGS[sid]:
handle_embedded_annot(data)
kg = KGS[sid]
query_classes = """
SELECT DISTINCT ?class { ?s rdf:type ?class } ORDER BY ?class
"""
query_properties = """
SELECT DISTINCT ?prop { ?s ?prop ?o } ORDER BY ?prop
"""
table_content = {"classes": [], "properties": []}
qres = kg.query(query_classes)
for row in qres:
table_content["classes"].append(
{"name": row["class"], "tag": {"OLS": None, "LOV": None, "BioPortal": None}}
)
print(f'{row["class"]}')
qres = kg.query(query_properties)
for row in qres:
table_content["properties"].append(
{"name": row["prop"], "tag": {"OLS": None, "LOV": None, "BioPortal": None}}
)
print(f'{row["prop"]}')
emit("done_check", table_content)
for c in table_content["classes"]:
if util.ask_OLS(c["name"]):
c["tag"]["OLS"] = True
else:
c["tag"]["OLS"] = False
emit("done_check", table_content)
if util.ask_LOV(c["name"]):
c["tag"]["LOV"] = True
else:
c["tag"]["LOV"] = False
emit("done_check", table_content)
if util.ask_BioPortal(c["name"], "class"):
c["tag"]["BioPortal"] = True
else:
c["tag"]["BioPortal"] = False
emit("done_check", table_content)
for p in table_content["properties"]:
if util.ask_OLS(p["name"]):
p["tag"]["OLS"] = True
else:
p["tag"]["OLS"] = False
emit("done_check", table_content)
if util.ask_LOV(p["name"]):
p["tag"]["LOV"] = True
else:
p["tag"]["LOV"] = False
emit("done_check", table_content)
if util.ask_BioPortal(p["name"], "property"):
p["tag"]["BioPortal"] = True
else:
p["tag"]["BioPortal"] = False
emit("done_check", table_content)
@DeprecationWarning
@socketio.on("check_kg_shape")
def check_kg_shape(data):
step = 0
sid = request.sid
print(sid)
uri = str(data["url"])
if not sid in KGS.keys():
handle_embedded_annot(data)
elif not KGS[sid]:
handle_embedded_annot(data)
kg = KGS[sid]
# TODO replace this code with profiles.bioschemas_shape_gen
warnings, errors = util.shape_checks(kg)
data = {"errors": errors, "warnings": warnings}
emit("done_check_shape", data)
# replacement
# results = bioschemas_shape.validate_any_from_microdata(uri)
# print(results)
@socketio.on("check_kg_shape_2")
def check_kg_shape_2(data):
print("shape validation started")
sid = request.sid
print(sid)
kg = KGS[sid]
if not kg:
print("cannot access current knowledge graph")
elif len(kg) == 0:
print("cannot validate an empty knowledge graph")
results = validate_any_from_KG(kg)
emit("done_check_shape", results)
#######################################
#######################################
def cb():
print("received message originating from server")
def buildJSONLD():
"""
Create the Advanced page JSON-LD annotation using schema.org
@return str
"""
repo = git.Repo(".")
tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
latest_tag = tags[-1]
jld = {
"@context": [
"https://schema.org/",
{"dct": "https://purl.org/dc/terms/"},
{"prov": "http://www.w3.org/ns/prov#"},
],
"@type": ["WebApplication", "prov:Entity"],
"@id": "https://github.com/IFB-ElixirFr/FAIR-checker",
"dct:conformsTo": "https://bioschemas.org/profiles/ComputationalTool/1.0-RELEASE",
"name": "FAIR-Checker",
"url": "https://fair-checker.france-bioinformatique.fr",
"applicationCategory": "Bioinformatics",
"applicationSubCategory": "Automated FAIR testing",
"softwareVersion": str(latest_tag),
"operatingSystem": "Any",
"description": """FAIR-Checker is a tool aimed at assessing FAIR principles and empowering data provider to enhance the quality of their digital resources.
Data providers and consumers can check how FAIR are web resources. Developers can explore and inspect metadata exposed in web resources.""",
"author": [
{
"@type": ["Person", "prov:Person"],
"@id": "https://orcid.org/0000-0003-0676-5461",
"givenName": "Thomas",
"familyName": "Rosnet",
"prov:actedOnBehalfOf": {"@id": "https://ror.org/045f7pv37"},
},
{
"@type": ["Person", "prov:Person"],
"@id": "https://orcid.org/0000-0002-3597-8557",
"givenName": "Alban",
"familyName": "Gaignard",
"prov:actedOnBehalfOf": {"@id": "https://ror.org/045f7pv37"},
},
{
"@type": ["Person", "prov:Person"],
"@id": "https://orcid.org/0000-0002-0399-8713",
"givenName": "Marie-Dominique",
"familyName": "Devignes",
"prov:actedOnBehalfOf": {"@id": "https://ror.org/045f7pv37"},
},
],
"citation": [
"https://dx.doi.org/10.1038%2Fsdata.2018.118",
"https://doi.org/10.5281/zenodo.5914307",
"https://doi.org/10.5281/zenodo.5914367",
],
"license": "https://spdx.org/licenses/MIT.html",
"prov:wasAttributedTo": [
{"@id": "https://orcid.org/0000-0003-0676-5461"},
{"@id": "https://orcid.org/0000-0002-3597-8557"},
{"@id": "https://orcid.org/0000-0002-0399-8713"},
],
}
raw_jld = json.dumps(jld)
return raw_jld
@app.route("/check", methods=["GET"])
def base_metrics():
"""
Load the Advanced page elements loading informations from FAIRMetrics API.
Generate a page allowing test of independent metrics.
@return render_template
"""
# unique id to retrieve content results of tests
content_uuid = str(uuid.uuid1())
DICT_TEMP_RES[content_uuid] = ""
print(str(session.items()))
# sid = request.sid
# return render_template('test_asynch.html')
# metrics = []
#
# metrics_res = METRICS_RES
#
# for metric in metrics_res:
# # remove "FAIR Metrics Gen2" from metric name
# name = metric["name"].replace('FAIR Metrics Gen2- ','')
# # same but other syntax because of typo
# name = name.replace('FAIR Metrics Gen2 - ','')
# metrics.append({
# "name": name,
# "description": metric["description"],
# "api_url": metric["smarturl"],
# "id": "metric_" + metric["@id"].rsplit('/', 1)[-1],
# "principle": metric["principle"],
# "principle_tag": metric["principle"].rsplit('/', 1)[-1],
# "principle_category": metric["principle"].rsplit('/', 1)[-1][0],
# })
raw_jld = buildJSONLD()
print(app.config)
metrics = []
for key in METRICS_CUSTOM.keys():
metrics.append(
{
"name": METRICS_CUSTOM[key].get_name(),
"implem": METRICS_CUSTOM[key].get_implem(),
"description": METRICS_CUSTOM[key].get_desc(),
"api_url": "API to define",
"id": METRICS_CUSTOM[key].get_id(),
"principle": METRICS_CUSTOM[key].get_principle(),
"principle_tag": METRICS_CUSTOM[key].get_principle_tag(),
"principle_category": METRICS_CUSTOM[key]
.get_principle()
.rsplit("/", 1)[-1][0],
}
)
# for key in METRICS.keys():
# print()
# metrics.append(
# {
# "name": METRICS[key].get_name(),
# "implem": METRICS[key].get_implem(),
# "description": METRICS[key].get_desc(),
# "api_url": METRICS[key].get_api(),
# "id": "metric_" + METRICS[key].get_id().rsplit("/", 1)[-1],
# "principle": METRICS[key].get_principle(),
# "principle_tag": METRICS[key].get_principle().rsplit("/", 1)[-1],
# "principle_category": METRICS[key]
# .get_principle()
# .rsplit("/", 1)[-1][0],
# }
# )
# response =
return make_response(
render_template(
"check.html",
f_metrics=metrics,
sample_data=sample_resources,
jld=raw_jld,
uuid=content_uuid,
title="Check",
subtitle="How FAIR is my resource ?",
)
)
# )).headers.add('Access-Control-Allow-Origin', '*')
# @app.after_request
# def after_request(response):
# response.headers.add('Access-Control-Allow-Origin', '*')
# response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
# response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
# return response
def update_bioschemas_valid(func):
@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
# Do something before
start_time = time.time()
value = func(*args, **kwargs)
# Do something after
elapsed_time = round((time.time() - start_time), 2)
logging.info(f"Bioschemas validation processed in {elapsed_time} s")
# emit("done_check_shape", res, namespace="/validate_bioschemas")
# socketio.emit("done_check_shape", res, namespace="/inspect")
return value
return wrapper_decorator
@app.route("/validate_bioschemas")
@update_bioschemas_valid
def validate_bioschemas():
uri = request.args.get("uri")
logging.debug(f"Validating Bioschemas markup fr {uri}")
res, kg = validate_any_from_microdata(input_url=uri)
m = []
return render_template(
"bioschemas.html",
results=res,
kg=kg,
f_metrics=m,
sample_data=sample_resources,
title="Inspect",
subtitle="to enhance metadata quality",
jld=buildJSONLD(),
)
@app.route("/inspect")
def kg_metrics_2():
# m = [{ "name": "i1",
# "description": "desc i1",
# "id": "metric_i1",
# "principle": "principle for i1" }]
m = []
return render_template(
"inspect.html",
f_metrics=m,
sample_data=sample_resources,
title="Inspect",
subtitle="to enhance metadata quality",
)
@app.route("/test_url", methods=["POST"])
def testUrl():
test_url = request.form.get("url")
number = test_metric.getMetrics()
# socketio.emit('newnumber', {'number': number}, namespace='/test')
socketio.emit("my response", {"data": "got it!"}, namespace="/test")
(
headers_list,
descriptions_list,
test_score_list,
time_list,
comments_list,
) = test_metric.webTestMetrics(test_url)
results_list = []
for i, elem in enumerate(headers_list):
if i != 0:
res_dict = {}
res_dict["header"] = headers_list[i]
res_dict["score"] = test_score_list[i]
res_dict["time"] = time_list[i]
try:
res_dict["comments"] = comments_list[i].replace("\n", "<br>")
res_dict["descriptions"] = descriptions_list[i]
except IndexError:
res_dict["comments"] = ""
res_dict["descriptions"] = ""
results_list.append(res_dict)
if i == 4:
print(res_dict)
return render_template(
"result.html",
test_url=test_url,
results_list=results_list,
)
parser = argparse.ArgumentParser(
description="""
FAIR-Checker, a web and command line tool to assess FAIRness of web accessible resources.
Usage examples :
python app.py --web
python app.py --url http://bio.tools/bwa
python app.py --bioschemas --url http://bio.tools/bwa
Please report any issue to <EMAIL>,
or submit an issue to https://github.com/IFB-ElixirFr/fair-checker/issues.
""",
formatter_class=RawTextHelpFormatter,
)
parser.add_argument(
"-d",
"--debug",
action="store_true",
required=False,
help="enables debugging logs",
dest="debug",
)
parser.add_argument(
"-w",
"--web",
action="store_true",
required=False,
help="launch FAIR-Checker as a web server",
dest="web",
)
# nargs='+'
parser.add_argument(
"-u",
"--urls",
nargs="+",
required=False,
help="list of URLs to be tested",
dest="urls",
)
parser.add_argument(
"-bs",
"--bioschemas",
action="store_true",
required=False,
help="validate Bioschemas profiles",
dest="bioschemas",
)
def get_result_style(result) -> str:
if result == Result.NO:
return "red"
elif result == Result.WEAK:
return "yellow"
elif result == Result.STRONG:
return "green"
return ""
if __name__ == "__main__":
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
if args.debug:
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)-8s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
else:
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)-8s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
LOGGER = logging.getLogger()
if not LOGGER.handlers:
LOGGER.addHandler(logging.StreamHandler(sys.stdout))
if args.urls:
start_time = time.time()
console = Console()
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Findable", justify="right")
table.add_column("Accessible", justify="right")
table.add_column("Interoperable", justify="right")
table.add_column("Reusable", justify="right")
for url in args.urls:
logging.debug(f"Testing URL {url}")
web_res = WebResource(url)
metrics_collection = []
metrics_collection.append(FAIRMetricsFactory.get_F1A(web_res))
metrics_collection.append(FAIRMetricsFactory.get_F1B(web_res))
metrics_collection.append(FAIRMetricsFactory.get_F2A(web_res))
metrics_collection.append(FAIRMetricsFactory.get_F2B(web_res))
metrics_collection.append(FAIRMetricsFactory.get_I1(web_res))
metrics_collection.append(FAIRMetricsFactory.get_I1A(web_res))
metrics_collection.append(FAIRMetricsFactory.get_I1B(web_res))
metrics_collection.append(FAIRMetricsFactory.get_I2(web_res))
metrics_collection.append(FAIRMetricsFactory.get_I2A(web_res))
metrics_collection.append(FAIRMetricsFactory.get_I2B(web_res))
metrics_collection.append(FAIRMetricsFactory.get_I3(web_res))
metrics_collection.append(FAIRMetricsFactory.get_R11(web_res))
metrics_collection.append(FAIRMetricsFactory.get_R12(web_res))
metrics_collection.append(FAIRMetricsFactory.get_R13(web_res))
if args.bioschemas:
logging.info("Bioschemas eval")
else:
for m in track(metrics_collection, "Processing FAIR metrics ..."):
logging.info(m.get_name())
res = m.evaluate()
if m.get_principle_tag().startswith("F"):
table.add_row(
Text(
m.get_name() + " " + str(res.get_score()),
style=get_result_style(res),
),
"",
"",
"",
)
elif m.get_principle_tag().startswith("A"):
table.add_row(
"",
Text(
m.get_name() + " " + str(res.get_score()),
style=get_result_style(res),
),
"",
"",
)
elif m.get_principle_tag().startswith("I"):
table.add_row(
"",
"",
Text(
m.get_name() + " " + str(res.get_score()),
style=get_result_style(res),
),
"",
)
elif m.get_principle_tag().startswith("R"):
table.add_row(
"",
"",
"",
Text(
f"{m.get_name()} {str(res.get_score())}",
style=get_result_style(res),
),
)
console.rule(f"[bold red]FAIRness evaluation for URL {url}")
console.print(table)
elapsed_time = round((time.time() - start_time), 2)
logging.info(f"FAIR metrics evaluated in {elapsed_time} s")
elif args.web:
logging.info("Starting webserver")
try:
socketio.run(app, host="127.0.0.1", port=5000, debug=True)
finally:
browser = WebResource.WEB_BROWSER_HEADLESS
browser.quit()
|
import os
import subprocess
import re
import sys
import requests
from bs4 import BeautifulSoup
import urllib
from ohno.gui import *
import tkinter as tk
from tkinter import ttk
import json
GREEN = '\033[92m'
GRAY = '\033[90m'
CYAN = '\033[36m'
RED = '\033[31m'
YELLOW = '\033[33m'
END = '\033[0m'
UNDERLINE = '\033[4m'
BOLD = '\033[1m'
def confirm():
option = {"yes": True, "y": True, "no": False, "n": False, "": True}
while True:
print(BOLD + YELLOW + "\nDo you want to search StackOverflow? [Y/N] " + END, end='')
choice = input().lower()
if choice in option:
return option[choice]
print("Please respond with ('yes' or 'no') or ('y' or 'n').\n")
# returns compiler
def get_lang(File_Path):
if File_Path.endswith(".py"):
return "python3 "
elif File_Path.endswith(".cpp"):
return "g++ "
elif File_Path.endswith(".java"):
return "javac "
elif File_Path.endswith(".c"):
return "gcc "
elif File_Path.endswith(".js"):
return "rhino "
else:
return None
# prints help
def print_help():
print("%sNAME%s\n\tOhno\n"%(BOLD,END))
print("%sSYNOPSIS%s\n\t%sohno%s %s[%sfile_name]%s\n" % (BOLD, END,BOLD, END, YELLOW,UNDERLINE,END))
print("\t%sohno%s -q %s[%scustom_query]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("\t%sohno%s --query %s[%scustom_query]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("\t%sohno%s -g %s[%scode_name]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("\t%sohno%s --gfg %s[%scode_name]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("\t%sohno%s -s %s[%scode_file]%s %s[%sinput_file]%s\n"%(BOLD, END, YELLOW,UNDERLINE, END, YELLOW, UNDERLINE,END) )
print("\t%sohno%s --submit %s[%scode_file]%s %s[%sinput_file]%s\n"%(BOLD, END, YELLOW,UNDERLINE, END, YELLOW, UNDERLINE,END) )
# print("\t%sohno%s -c %s%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
# print("\t%sohno%s --calender %s%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("%sDESCRIPTION%s\n\t\n"%(BOLD,END))
def cprint_help():
print("%sNAME%s\n\tcprog\n"%(BOLD,END))
print("\t%sohno%s -c %s[%scode_name]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("\t%sohno%s --codechef %s[%scode_name]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("\t%sohno%s -s %s[%scode_name]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("\t%sohno%s --spoj %s[%scode_name]%s\n"%(BOLD, END, YELLOW,UNDERLINE,END) )
print("%sDESCRIPTION%s\n\t\n"%(BOLD,END))
def error_on_python(error):
list_err = []
if any(err in error for err in["KeyboardInterrupt", "SystemExit", "GeneratorExit"]):
return None
else:
list_err.append(error.split('\n')[-2].strip())
return list_err
def error_on_java(error):
list_err = []
length = len(error.split('\n'))
for i in range(length):
m = re.search(r'.*error:(.*)', error.split('\n')[i])
if m:
list_err.append(m.group(1).strip())
return list_err
def error_on_cpp(error):
list_err = []
length = len(error.split('\n'))
for i in range(length):
m = re.search(r".*error:(.*)", error.split('\n')[i])
if m:
list_err.append(m.group(1).strip())
for i in range(len(list_err)):
list_err[i] = list_err[i][:list_err[i].find("(")]
list_err[i] = list_err[i][:list_err[i].find("{")]
list_err[i] = list_err[i][:list_err[i].find("[")]
return list_err
def error_on_c(error):
list_err = []
length = len(error.split('\n'))
for i in range(length):
m = re.search(r".*error:(.*)", error.split('\n')[i])
if m:
list_err.append(m.group(1).strip())
for i in range(length):
m = re.search(r".*warning:(.*)", error.split('\n')[i])
if m:
list_err.append(m.group(1).strip())
for i in range(len(list_err)):
list_err[i] = list_err[i][:list_err[i].find("(")]
list_err[i] = list_err[i][:list_err[i].find("{")]
list_err[i] = list_err[i][:list_err[i].find("[")]
return list_err
def error_on_js(error):
list_err = []
list_err.append(error.split('\n')[0][4:].strip())
for i in range(len(list_err)):
list_err[i] = list_err[i][:list_err[i].find("(")]
list_err[i] = list_err[i][:list_err[i].find(":")+2]
list_err[i] = list_err[i][:list_err[i].find("{")]
list_err[i] = list_err[i][:list_err[i].find("[")]
return list_err
def get_error(error, language):
if error == "":
return None
elif language == "python3 ":
return error_on_python(error)
elif language == "javac ":
return error_on_java(error)
elif language == "g++ ":
return error_on_cpp(error)
elif language == "gcc ":
return error_on_c(error)
elif language == "rhino ":
return error_on_js(error)
else:
return None
def execute(command):
sp = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err=sp.communicate()
return (out.decode('utf-8'), err.decode('utf-8'))
def scrap(errors_list):
global stack_questions_list
stack_questions_list = []
for error in errors_list:
params = {"q": error}
error_next = urllib.parse.urlencode(params)
url="https://stackoverflow.com/search?pagesize=3&"+error_next
page=requests.get(url)
html_doc=page.text
soup=BeautifulSoup(html_doc,'lxml')
all_a_tags_questions=soup.find_all('a',class_="question-hyperlink")
all_stats_tags_for_answer=soup.find_all('div',class_=["c","status"])
i=0
for question in all_a_tags_questions:
if i>=10:
break
stack_questions_list.append([(question.text).strip(),question['href']])
i=i+1
i=0
for each_strong in all_stats_tags_for_answer:
if i>=10:
break
each_strong.find('strong')
stack_questions_list[i].append((each_strong.text).strip())
i=i+1
util(stack_questions_list)
def get_lang_for_exec(File_Path):
if File_Path.endswith(".py"):
return "python3"
elif File_Path.endswith(".cpp"):
return "cpp"
elif File_Path.endswith(".java"):
return "java"
elif File_Path.endswith(".c"):
return "c"
elif File_Path.endswith(".php"):
return "php"
elif File_Path.endswith(".pl"):
return "perl"
elif File_Path.endswith(".rb"):
return "ruby"
elif File_Path.endswith(".go"):
return "go"
elif File_Path.endswith(".sh"):
return "bash"
elif File_Path.endswith(".sql"):
return "sql"
elif File_Path.endswith(".pas"):
return "pascal"
elif File_Path.endswith(".cs"):
return "csharp"
elif File_Path.endswith(".r"):
return "r"
elif File_Path.endswith(".js"):
return "rhino"
elif File_Path.endswith(".m"):
return "octave"
elif File_Path.endswith(".coffee"):
return "coffeescript"
elif File_Path.endswith(".b"):
return "brainfuck"
elif File_Path.endswith(".swift"):
return "swift"
elif File_Path.endswith(".lua"):
return "lua"
elif File_Path.endswith(".kt"):
return "kotlin"
else:
return None
def submit():
clientId = "<KEY>"
clientSecret = "5b9748536e29f2c9e360e82fa2b59865f4d6540eea17ffe5401c58bf3923de5c"
script = open(sys.argv[2], 'r').read()
stdin = ""
if len(sys.argv) > 3: # change when -s is introduced
stdin = open(sys.argv[3], 'r').read()
language = get_lang_for_exec(sys.argv[2])
versionIndex = "2"
if language == "brainfuck" or language == "rhino":
versionIndex = "0"
if language == "kotlin" or language == "lua":
versionIndex = "1"
# print(stdin)
''' To check credits spent '''
# credit = {"clientId": clientId,"clientSecret": clientSecret}
# check_credits = requests.post(url = "https://api.jdoodle.com/v1/credit-spent", json=credit)
# print(check_credits.text)
data = {"clientId": clientId,"clientSecret": clientSecret,"script":script,"stdin":stdin,"language":language,"versionIndex":versionIndex}
req = requests.post(url = "https://api.jdoodle.com/v1/execute", json=data)
# print(req.text)
answer = json.loads(req.text)
error = False
if answer["memory"] == None and answer["cpuTime"] == None:
error = True
if error == False:
print(answer["output"])
print("\nMemory used: "+ GREEN + BOLD + answer["memory"] + END)
print("\nCPU Time: "+ GREEN + BOLD + answer["cpuTime"] + END)
else:
if answer["output"] == "\n\n\n JDoodle - Timeout \nIf your program reads input, please enter the inputs in STDIN box above or try enable \"Interactive\" mode option above.\nPlease check your program has any endless loop. \nContact JDoodle support at <EMAIL> for more information.":
print(RED + BOLD + "Please input the STDIN file as an argument!" + END)
else:
if language == "python3":
language = "python3 "
elif language == "java":
language = "javac "
elif language == "cpp":
language = "g++ "
elif language == "c":
language = "gcc "
elif language == "rhino":
language = "rhino "
else:
language = None
if language == None:
print(CYAN + BOLD + "Currently search on stackoverflow is available only for C, C++, Java, Python and JavaScript!!!")
else:
print(answer["output"])
err = answer["output"]
all_error = []
if confirm():
all_error.append(get_error(err, language))
scrap(all_error[0])
|
import os
from tempfile import TemporaryDirectory
import pystac
from stactools.testing import CliTestCase
from stactools.aafc_landuse.commands import create_aafclanduse_command
from tests import test_data
class CreateItemTest(CliTestCase):
def create_subcommand_functions(self):
return [create_aafclanduse_command]
def test_create_collection(self):
with TemporaryDirectory() as tmp_dir:
result = self.run_command(
["aafclanduse", "create-collection", "-d", tmp_dir])
self.assertEqual(result.exit_code,
0,
msg="\n{}".format(result.output))
jsons = [p for p in os.listdir(tmp_dir) if p == "collection.json"]
self.assertEqual(len(jsons), 1)
collection = pystac.read_file(os.path.join(tmp_dir, jsons[0]))
collection.validate()
def test_create_cog_and_item(self):
with TemporaryDirectory() as tmp_dir:
test_path = test_data.get_path("data-files")
test_path = next((os.path.join(test_path, f)
for f in os.listdir(test_path)
if f.lower().endswith(".tif")))
# Create a COG and item
result = self.run_command(
["aafclanduse", "create-cog", test_path, tmp_dir])
self.assertEqual(result.exit_code,
0,
msg="\n{}".format(result.output))
cog_path = os.path.join(
tmp_dir,
os.path.basename(test_path)[:-4] + "_cog.tif")
self.assertTrue(os.path.isfile(cog_path))
cmd = ["aafclanduse", "create-item", "-c", cog_path, "-d", tmp_dir]
result = self.run_command(cmd)
self.assertEqual(result.exit_code,
0,
msg="\n{}".format(result.output))
# Validate item
jsons = [p for p in os.listdir(tmp_dir) if p.endswith(".json")]
self.assertEqual(len(jsons), 1)
item_path = os.path.join(tmp_dir, jsons[0])
item = pystac.read_file(item_path)
asset = item.assets["landuse"]
self.assertIn("data", asset.roles)
# Projection Extension
self.assertIn("proj:epsg", asset.extra_fields)
self.assertIn("proj:bbox", asset.extra_fields)
self.assertIn("proj:transform", asset.extra_fields)
self.assertIn("proj:shape", asset.extra_fields)
self.assertIn("proj:bbox", item.properties)
self.assertIn("proj:transform", item.properties)
self.assertIn("proj:shape", item.properties)
# File Extension
self.assertIn("file:size", asset.extra_fields)
self.assertIn("file:values", asset.extra_fields)
self.assertGreater(len(asset.extra_fields["file:values"]), 0)
# Raster Extension
self.assertIn("raster:bands", asset.extra_fields)
self.assertEqual(len(asset.extra_fields["raster:bands"]), 1)
self.assertIn("nodata", asset.extra_fields["raster:bands"][0])
self.assertIn("sampling", asset.extra_fields["raster:bands"][0])
self.assertIn("data_type", asset.extra_fields["raster:bands"][0])
self.assertIn("spatial_resolution",
asset.extra_fields["raster:bands"][0])
# Label Extension
self.assertIn("labels", asset.roles)
self.assertIn("labels-raster", asset.roles)
item.validate()
|
from collections import defaultdict
from contextlib import closing
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Optional
import numpy as np # type: ignore
import pandas as pd # type: ignore
from tables import Filters # type: ignore
from tables import open_file
from pullframe import api
from pullframe.types import CacheFormat
class PyTables(api.Persist):
def __init__(
self, directory: Path, complib: str = "blosc", complevel: int = 9
):
super().__init__(directory)
self.complib = complib
self.complevel = complevel
@classmethod
def on(cls, directory: Path) -> "PyTables":
return cls(directory)
def load(
self,
name: str,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
include_start: bool = True,
) -> pd.DataFrame:
with self.__reading_name(name) as h5:
return _read_from_f(h5, start, end, include_start)
def save(self, name: str, df: pd.DataFrame) -> None:
if not self.exists(name):
return self.write(name, df)
prev = self.load(name)
new = prev.reindex(
index=prev.index.union(df.index),
columns=prev.columns.union(df.columns),
)
new.loc[df.index, df.columns] = df.values
self.write(name, new)
def exists(self, name: str) -> bool:
return self.path(name).exists()
def last_index(self, name: str) -> datetime:
with self.__reading_name(name) as h5:
return _load_index(h5)[-1]
def update(self, name: str, path: Path) -> None:
with self.__reading_file(path) as h5:
append = _read_from_f(h5)
self.save(name, append)
@classmethod
def format(cls):
return CacheFormat.PYTABLES
@staticmethod
def suffix():
return "h5"
def write(self, name: str, df: pd.DataFrame) -> None:
self.dump(self.path(name), df)
def dump(self, path: Path, df: pd.DataFrame) -> None:
with self.__writing_file(path) as h5:
_write_to_f(h5, df)
def __reading_name(self, name: str):
return self.__reading_file(self.path(name))
def __reading_file(self, path: Path):
return closing(open_file(path, mode="r"))
def __writing_file(self, path: Path):
filters = Filters(complib=self.complib, complevel=self.complevel)
return closing(open_file(path, mode="w", filters=filters))
Index = int
def _read_from_f(
h5,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
include_start=True,
) -> pd.DataFrame:
index = _load_index(h5)
if start is None:
start_idx: int = 0
else:
start_idx = np.searchsorted(index, start)
if not include_start:
start_idx = max(0, start_idx + 1)
if end is None:
end_idx: int = len(index) # type: ignore
else:
end_idx = np.searchsorted(index, end, side="right")
all_columns = h5.get_node(h5.root, "all_columns").read()
dtypes = h5.get_node(h5.root, "dtypes").read()
df_list = []
for dtyp in dtypes:
node = f"/data/{dtyp.decode()}"
values = h5.get_node(node, "data")[start_idx:end_idx]
columns = h5.get_node(node, "columns").read()
if dtyp == b"str":
values = values.astype("str")
elif dtyp == b"datetime":
values = np.vstack(
[pd.to_datetime(values[:, i]) for i in range(values.shape[1])]
).T
df = pd.DataFrame(
index=index[start_idx:end_idx], columns=columns, data=values
)
df_list.append(df)
df = pd.concat(df_list, axis=1)[all_columns]
if df.columns.dtype == "object":
df.columns = [i.decode() for i in df.columns]
return df
def _load_index(h5):
index = h5.get_node(h5.root, "index").read()
return pd.to_datetime(index)
def _write_to_f(h5, df: pd.DataFrame) -> None:
dtype_to_col_indexes = _dtype_to_col_indexes(df.dtypes)
h5.create_array(
h5.root, "index", df.index.values.astype(np.float64), "index"
)
h5.create_array(h5.root, "all_columns", df.columns.tolist(), "all_columns")
data_grp = h5.create_group(h5.root, "data", "data group")
h5.create_array(
h5.root,
"dtypes",
[_name(i) for i in dtype_to_col_indexes.keys()],
"dtypes",
)
for dtype, indexes in dtype_to_col_indexes.items():
data = df.iloc[:, indexes]
dtype_name = _name(dtype)
group = h5.create_group(data_grp, dtype_name, f"{dtype_name} group")
if dtype_name == "str":
arr = data.values
arr = arr.astype("U")
elif dtype_name == "datetime":
arr = data.values.astype(np.float64)
else:
arr = data.values
h5.create_carray(
where=group, name="data", obj=arr, title=f"{dtype_name} data"
)
h5.create_array(
group, "columns", data.columns.tolist(), f"{dtype_name} columns"
)
def _dtype_to_col_indexes(dtypes) -> Dict[np.dtype, List[Index]]:
result = defaultdict(list)
for i, dtype in enumerate(dtypes):
result[dtype].append(i)
return result
def _name(dtype):
if dtype.name == "object":
return "str"
elif dtype.name == "datetime64[ns]":
return "datetime"
else:
return dtype.name
|
# %% [markdown]
'''
# Fit a line with Singular Value Decomposition
'''
# %% [markdown]
'''
Singular value decomposition (SVD) is a widely used method that plays a huge role in data preprocessing for machine learning.
It is mostly used to filter out noise from the data, reduce its dimensionnality/complexity and to have uncorrelated features.
SVD will extract the best meaningfull mathematical basis that describe much the data using linear algebra.
'''
# %% [markdown]
'''
## tl;dr
1. Organize your input data as a $d\times n$ matrix.
2. Center the data by subtracting the mean from the matrix.
3. Use SVD to extract eigen vectors from the data, the first vector is the direction of the line.
4. The parametric form of the line is described by the direction and average.
5. Calculate any point of the line by fixing the free parameter.
'''
# %% [markdown]
'''
## 1. Theory
'''
# %% [markdown]
'''
The key idea behind SVD is that any matrix $M$ with positive determinant can be factorized in the form :
\begin{equation}
M = U\Sigma V^*
\end{equation}
Where $U$ and $V^*$ are rotation matrices and $\Sigma$ is a scale matrix.
Here $V^*$ wil give you the set of vector to project the data onto the new dimension space.
Check in the following figure, the axis $y_1$ best explain the data because when you project the data into $y_1$, the variance is higher than for $y_2$.
<img src="imgs/line_svd/svd.svg" alt="manifold" style="width: 400px;"/>
For the rest of this tutorial, we will use SVD to fit a 3-dimensionnal line based on some random 3D points (but this method can be extended to $n$-d).
'''
# %% [markdown]
'''
## 2. Data generation
'''
# %% [markdown]
'''
First, we generate $n$ points with a random gaussian noise.
We organize the input data according to a $d$×$n$ matrix, where $d$ is the number of dimensions (or features) and $n$ the number of samples.
'''
# %%
## imports
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
# fixing numpy random state for reproducibility
np.random.seed(0)
# %%
# input data
n = 25
points = np.array( [5*np.arange(n),5+5*np.arange(n),5*np.ones(n)] ).T + 0.5-np.random.rand(n,3)
points
# %% [markdown]
'''
## 3. Performing SVD
'''
# %% [markdown]
'''
Before performing SVD, it is necessary to center the data by subtracting the mean of the data. Without centering, the first eigen vector would explain all the data.
This is because this method performs just scaling (as we saw earlier), but cannot take into account the bias of the data (i.e. the intercept in linear regression).
Sometimes it can also be usefull to normalize the input, because our data has not huge difference in each dimension we don't need to.
We will use [linear algebra package from numpy](https://docs.scipy.org/doc/numpy/reference/routines.linalg.html) for the SVD.
'''
# %%
# calculating the mean of the points
avg = np.mean(points, axis=0)
# subtracting the mean from all points
subtracted = points - avg
# performing SVD
_, _, V = np.linalg.svd(subtracted)
# %% [markdown]
'''
## 4. Finding the line
'''
# %% [markdown]
'''
To estimate the equation of a line, we need its direction (a vector) and one point that goes trough that line.
Previously, we performed SVD and extracted $V^*$ matrix that describe the eigen vectors. The first eigen vector is the one that best describe the data,
which in our case is the line that best fits all the points!
One example of a point that can go through this line is the average of the sample that we calculated previously. Then, any point of the line can be given by:
\begin{equation}
p(t) = p_0 + dt
\end{equation}
Where $t$ is the free parameter that is allowed to be any real number.
'''
# %%
# find the direction vector (which is the right singular vector corresponding to the largest singular value)
direction = V[0, :]
# A line is defined by the average and its direction
p0 = avg
d = direction
print(d)
# %% [markdown]
'''
We can calculate the angle $\alpha$ between two lines with direction $d_0$ and $d_1$ using:
\begin{equation}
\alpha = \arccos\Big(\frac{d_a.d_b}{\|d_a\|.\|d_b\|}\Big)
\end{equation}
For example, this is the angle between our line and the normal axis $(0, 0, 1)$.
'''
# %%
d0 = np.array([0, 0, 1])
angle = np.arccos(np.dot(d0,d)/(np.linalg.norm(d0) * np.linalg.norm(d)))
print(angle*180/np.pi)
# %% [markdown]
'''
## 5. Plotting the line
'''
# %% [markdown]
'''
Using the parametric form of the line, we can extract two different points by fixing the free parameter (make sure to choose a big one).
'''
# %%
pa = p0 + (-100)*d
pb = p0 + 100*d
# %% [markdown]
'''
To plot the 3D line, we will use [plotly](https://plot.ly/python/) that have really good html embeddings and smooth 3D rendering.
'''
# %%
## plotly
trace1 = go.Scatter3d(
x=[pa[0],pb[0]],
y=[pa[1],pb[1]],
z=[pa[2],pb[2]],
mode='lines',
name='3D fitted line',
line=go.scatter3d.Line(color='rgb(255,0,0)', width=10),
hoverinfo='none')
labels = []
for i in range(n): labels += [str(i)]
trace2 = go.Scatter3d(
x=points[:,0],
y=points[:,1],
z=points[:,2],
mode='markers',
name='Points',
marker=go.scatter3d.Marker(
symbol='cross',
opacity=1,
color='rgb(0,200,127)'),
text=labels,
hoverinfo='text')
layout = go.Layout(
title="3D line fitting",
scene=go.layout.Scene(
xaxis_title="x",
yaxis_title="y",
zaxis_title="z",
camera=dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=0, y=2.5, z=0))))
fig=go.Figure(data=[trace1, trace2], layout=layout)
fig.show(renderer="iframe_connected", config={'showLink': False})
# %% [markdown]
'''
## To go further
'''
# %% [markdown]
'''
If you want improve your understanding of SVD and its relation with PCA, check this [nice paper](https://arxiv.org/pdf/1404.1100.pdf) on the web.
On the importance of data normalization, check [this thread](https://stats.stackexchange.com/questions/22329/how-does-centering-the-data-get-rid-of-the-intercept-in-regression-and-pca).
'''
# %% [markdown]
'''
## Tags
'''
# %% [markdown]
'''
Data-Science; Geometry; Linear-Algebra
''' |
<filename>tests/parsers/test_jsonstring.py
import os
from langumo.parsers import EscapedJSONStringParser
from langumo.utils import AuxiliaryFile
def _get_resource_path(name: str) -> str:
return os.path.join(os.path.dirname(__file__), 'resources', name)
def test_json_string_parser_extraction():
parser = EscapedJSONStringParser()
# Load a dummy escaped json-string file.
raw = AuxiliaryFile(_get_resource_path('dummy.jsonstring.txt'))
parser.prepare(raw)
# Extract documents from the parser.
documents = list(parser.extract(raw))
# The dummy dump file contains 3 full articles and others are empty.
assert len(documents) == 3
def test_if_parser_parses_escaped_json_string_well():
parser = EscapedJSONStringParser()
# Load a dummy escaped json-string file.
raw = AuxiliaryFile(_get_resource_path('dummy.jsonstring.txt'))
parser.prepare(raw)
# Extract documents and parse the json-encoded strings.
articles = []
for document in parser.extract(raw):
article = parser.parse(document)
if article:
articles.append(article)
assert (articles == ['Wikipedia is a multilingual online encyclopedia '
'created and maintained as an op en collaboration '
'project by a community of volunteer editors using a '
'wiki-based editing system. It is the largest and '
'most popular general reference work on the World '
'Wide Web. It is also one of the 15 most popular '
'websites as ranked by Alexa, as of August 2020. It '
'features exclusively free content and has no '
'advertising. It is hosted by the Wikimedia '
'Foundation, an American non-profit organization '
'funded primarily through donations.\nWikipedia was '
'launched on January 15, 2001, and was created by '
'<NAME> and <NAME>. Sanger coined its '
'name as a portmanteau of the terms "wiki" and '
'"encyclopedia". Initially an English-language '
'encyclopedia, versions of Wikipedia in other '
'languages were quickly developed. With 6.2 million '
'articles, the English Wikipedia is the largest of '
'the more than 300 Wikipedia encyclopedias. Overall, '
'Wikipedia comprises more than 54 million articles '
'attracting 1.5 billion unique visitors per month.',
'In 2005, Nature published a peer review comparing '
'42 hard science articles from Encyclopædia '
'Britannica and Wikipedia and found that '
'Wikipedia\'s level of accuracy approached that of '
'Britannica, although critics suggested that it '
'might not have fared so well in a similar study of '
'a random sampling of all articles or one focused on '
'social science or contentious social issues. The '
'following year, Time stated that the open-door '
'policy of allowing anyone to edit had made '
'Wikipedia the biggest and possibly the best '
'encyclopedia in the world, and was a testament to '
'the vision of Jimmy Wales.\nWikipedia has been '
'criticized for exhibiting systemic bias and for '
'being subject to manipulation and spin in '
'controversial topics; <NAME> has criticized '
'Wikipedia for presenting a mixture of "truth, half '
'truth, and some falsehoods". Wikipedia has also '
'been criticized for gender bias, particularly on '
'its English-language version, where the dominant '
'majority of editors are male. However, edit-a-thons '
'have been held to encourage female editors and '
'increase the coverage of women\'s topics. Facebook '
'announced that by 2017 it would help readers detect '
'fake news by suggesting links to related Wikipedia '
'articles. YouTube announced a similar plan in 2018.',
'Other collaborative online encyclopedias were '
'attempted before Wikipedia, but none were as '
'successful. Wikipedia began as a complementary '
'project for Nupedia, a free online English-language '
'encyclopedia project whose articles were written by '
'experts and reviewed under a formal process. It was '
'founded on March 9, 2000, under the ownership of '
'Bomis, a web portal company. Its main figures were '
'Bomis CEO <NAME> and <NAME>, '
'editor-in-chief for Nupedia and later Wikipedia. '
'Nupedia was initially licensed under its own '
'Nupedia Open Content License, but even before '
'Wikipedia was founded, Nupedia switched to the GNU '
'Free Documentation License at the urging of Richard '
'Stallman. Wales is credited with defining the goal '
'of making a publicly editable encyclopedia, while '
'Sanger is credited with the strategy of using a '
'wiki to reach that goal. On January 10, 2001, '
'Sanger proposed on the Nupedia mailing list to '
'create a wiki as a "feeder" project for Nupedia.\n'
'The domains wikipedia.com and wikipedia.org were '
'registered on January 12, 2001 and January 13, 2001 '
'respectively, and Wikipedia was launched on January '
'15, 2001, as a single English-language edition at '
'www.wikipedia.com, and announced by Sanger on the '
'Nupedia mailing list. Wikipedia\'s policy of '
'"neutral point-of-view" was codified in its first '
'few months. Otherwise, there were relatively few '
'rules initially and Wikipedia operated '
'independently of Nupedia. Originally, Bomis '
'intended to make Wikipedia a business for profit.'])
|
<filename>fastmri/pl_modules/singlecoil_varnet_module.py
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from argparse import ArgumentParser
import fastmri
import torch
from fastmri.data import transforms
from fastmri.models import VarNet
from .mri_module import MriModule
class VarNetModule(MriModule):
"""
VarNet training module.
This can be used to train variational networks from the paper:
<NAME> et al. End-to-end variational networks for accelerated MRI
reconstruction. In International Conference on Medical Image Computing and
Computer-Assisted Intervention, 2020.
which was inspired by the earlier paper:
<NAME> et al. Learning a variational network for reconstruction of
accelerated MRI data. Magnetic Resonance inMedicine, 79(6):3055–3071, 2018.
"""
def __init__(
self,
num_cascades: int = 12,
pools: int = 4,
chans: int = 18,
lr: float = 0.0003,
lr_step_size: int = 40,
lr_gamma: float = 0.1,
weight_decay: float = 0.0,
**kwargs,
):
"""
Args:
num_cascades: Number of cascades (i.e., layers) for variational
network.
pools: Number of downsampling and upsampling layers for cascade
U-Net.
chans: Number of channels for cascade U-Net.
lr: Learning rate.
lr_step_size: Learning rate step size.
lr_gamma: Learning rate gamma decay.
weight_decay: Parameter for penalizing weights norm.
"""
super().__init__(**kwargs)
self.save_hyperparameters()
self.num_cascades = num_cascades
self.pools = pools
self.chans = chans
self.lr = lr
self.lr_step_size = lr_step_size
self.lr_gamma = lr_gamma
self.weight_decay = weight_decay
self.varnet = VarNet(
num_cascades=self.num_cascades,
chans=self.chans,
pools=self.pools,
)
self.loss = fastmri.SSIMLoss()
def forward(self, masked_kspace, mask):
return self.varnet(masked_kspace, mask)
def training_step(self, batch, batch_idx):
masked_kspace, mask, target, _, _, max_value, _ = batch
output = self(masked_kspace, mask)
target, output = transforms.center_crop_to_smallest(target, output)
loss = self.loss(output.unsqueeze(1), target.unsqueeze(1), data_range=max_value)
self.log("train_loss", loss)
return loss
def validation_step(self, batch, batch_idx):
masked_kspace, mask, target, fname, slice_num, max_value, _ = batch
output = self.forward(masked_kspace, mask)
target, output = transforms.center_crop_to_smallest(target, output)
return {
"batch_idx": batch_idx,
"fname": fname,
"slice_num": slice_num,
"max_value": max_value,
"output": output,
"target": target,
"val_loss": self.loss(
output.unsqueeze(1), target.unsqueeze(1), data_range=max_value
),
}
def test_step(self, batch, batch_idx):
masked_kspace, mask, _, fname, slice_num, _, crop_size = batch
crop_size = crop_size[0] # always have a batch size of 1 for varnet
output = self(masked_kspace, mask)
# check for FLAIR 203
if output.shape[-1] < crop_size[1]:
crop_size = (output.shape[-1], output.shape[-1])
output = transforms.center_crop(output, crop_size)
return {
"fname": fname,
"slice": slice_num,
"output": output.cpu().numpy(),
}
def configure_optimizers(self):
optim = torch.optim.Adam(
self.parameters(), lr=self.lr, weight_decay=self.weight_decay
)
scheduler = torch.optim.lr_scheduler.StepLR(
optim, self.lr_step_size, self.lr_gamma
)
return [optim], [scheduler]
@staticmethod
def add_model_specific_args(parent_parser): # pragma: no-cover
"""
Define parameters that only apply to this model
"""
parser = ArgumentParser(parents=[parent_parser], add_help=False)
parser = MriModule.add_model_specific_args(parser)
# param overwrites
# network params
parser.add_argument(
"--num_cascades",
default=12,
type=int,
help="Number of VarNet cascades",
)
parser.add_argument(
"--pools",
default=4,
type=int,
help="Number of U-Net pooling layers in VarNet blocks",
)
parser.add_argument(
"--chans",
default=18,
type=int,
help="Number of channels for U-Net in VarNet blocks",
)
# training params (opt)
parser.add_argument(
"--lr", default=0.0003, type=float, help="Adam learning rate"
)
parser.add_argument(
"--lr_step_size",
default=40,
type=int,
help="Epoch at which to decrease step size",
)
parser.add_argument(
"--lr_gamma",
default=0.1,
type=float,
help="Extent to which step size should be decreased",
)
parser.add_argument(
"--weight_decay",
default=0.0,
type=float,
help="Strength of weight decay regularization",
)
return parser
|
<gh_stars>0
import datetime
from collections import OrderedDict
from Poem.api import views_internal as views
from Poem.poem import models as poem_models
from Poem.tenants.models import Tenant
from Poem.users.models import CustUser
from django_tenants.test.cases import TenantTestCase
from django_tenants.test.client import TenantRequestFactory
from django_tenants.utils import schema_context, get_public_schema_name, \
get_tenant_domain_model
from rest_framework import status
from rest_framework.test import force_authenticate
from .utils_test import encode_data
class ListUsersAPIViewTests(TenantTestCase):
def setUp(self):
self.factory = TenantRequestFactory(self.tenant)
self.view = views.ListUsers.as_view()
self.url = '/api/v2/internal/users/'
self.tenant_user1 = CustUser.objects.create_user(
username='testuser',
first_name='Test',
last_name='User',
email='<EMAIL>',
date_joined=datetime.datetime(2015, 1, 1, 0, 0, 0),
)
self.tenant_user2 = CustUser.objects.create_user(
username='another_user',
first_name='Another',
last_name='User',
email='<EMAIL>',
is_superuser=True,
date_joined=datetime.datetime(2015, 1, 2, 0, 0, 0)
)
poem_models.UserProfile.objects.create(user=self.tenant_user1)
poem_models.UserProfile.objects.create(user=self.tenant_user2)
with schema_context(get_public_schema_name()):
self.super_tenant = Tenant.objects.create(
name='public', schema_name=get_public_schema_name()
)
get_tenant_domain_model().objects.create(
domain='public', tenant=self.super_tenant, is_primary=True
)
self.user1 = CustUser.objects.create_user(
username='Alan_Ford',
first_name='Alan',
last_name='Ford',
email='<EMAIL>',
date_joined=datetime.datetime(2019, 1, 1, 0, 0, 0)
)
self.user2 = CustUser.objects.create_user(
username='Number1',
first_name='Number',
last_name='One',
email='<EMAIL>',
is_superuser=True,
date_joined=datetime.datetime(1970, 1, 1, 0, 0, 0)
)
self.groupofmetrics = poem_models.GroupOfMetrics.objects.create(
name='Metric1'
)
self.groupofmetricprofiles = \
poem_models.GroupOfMetricProfiles.objects.create(name='MP1')
self.groupofaggregations = \
poem_models.GroupOfAggregations.objects.create(name='Aggr1')
def test_get_users_sp_superuser(self):
with schema_context(get_public_schema_name()):
request = self.factory.get(self.url)
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(
response.data,
[
{
'first_name': 'Alan',
'last_name': 'Ford',
'username': 'Alan_Ford',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2019-01-01 00:00:00',
'last_login': '',
'pk': self.user1.pk
},
{
'first_name': 'Number',
'last_name': 'One',
'username': 'Number1',
'is_active': True,
'is_superuser': True,
'email': '<EMAIL>',
'date_joined': '1970-01-01 00:00:00',
'last_login': '',
'pk': self.user2.pk
}
]
)
def test_get_users_sp_user(self):
with schema_context(get_public_schema_name()):
request = self.factory.get(self.url)
request.tenant = self.super_tenant
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(
response.data,
[
{
'first_name': 'Alan',
'last_name': 'Ford',
'username': 'Alan_Ford',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2019-01-01 00:00:00',
'last_login': '',
'pk': self.user1.pk
}
]
)
def test_get_users_tenant_superuser(self):
request = self.factory.get(self.url)
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(
response.data,
[
{
'first_name': 'Another',
'last_name': 'User',
'username': 'another_user',
'is_active': True,
'is_superuser': True,
'email': '<EMAIL>',
'date_joined': '2015-01-02 00:00:00',
'last_login': '',
'pk': self.tenant_user2.pk
},
{
'first_name': 'Test',
'last_name': 'User',
'username': 'testuser',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2015-01-01 00:00:00',
'last_login': '',
'pk': self.tenant_user1.pk
}
]
)
def test_get_users_tenant_user(self):
request = self.factory.get(self.url)
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(
response.data,
[
{
'first_name': 'Test',
'last_name': 'User',
'username': 'testuser',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2015-01-01 00:00:00',
'last_login': '',
'pk': self.tenant_user1.pk
}
]
)
def test_get_users_permission_denied_in_case_no_authorization(self):
request = self.factory.get(self.url)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_get_user_by_username_sp_superuser(self):
with schema_context(get_public_schema_name()):
request = self.factory.get(self.url + 'Alan_Ford')
force_authenticate(request, user=self.user2)
response = self.view(request, 'Alan_Ford')
self.assertEqual(
response.data,
{
'first_name': 'Alan',
'last_name': 'Ford',
'username': 'Alan_Ford',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2019-01-01 00:00:00',
'last_login': '',
'pk': self.user1.pk
}
)
def test_get_user_by_username_sp_user(self):
with schema_context(get_public_schema_name()):
request = self.factory.get(self.url + 'Alan_Ford')
force_authenticate(request, user=self.user1)
response = self.view(request, 'Alan_Ford')
self.assertEqual(
response.data,
{
'first_name': 'Alan',
'last_name': 'Ford',
'username': 'Alan_Ford',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2019-01-01 00:00:00',
'last_login': '',
'pk': self.user1.pk
}
)
def test_get_user_by_username_sp_user_another_username(self):
with schema_context(get_public_schema_name()):
request = self.factory.get(self.url + 'Number1')
force_authenticate(request, user=self.user1)
response = self.view(request, 'Number1')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(
response.data['detail'],
'You do not have permission to fetch users other than yourself.'
)
def test_get_user_by_username_tenant_superuser(self):
request = self.factory.get(self.url + 'testuser')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request, 'testuser')
self.assertEqual(
response.data,
{
'first_name': 'Test',
'last_name': 'User',
'username': 'testuser',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2015-01-01 00:00:00',
'last_login': '',
'pk': self.tenant_user1.pk
}
)
def test_get_user_by_username_tenant_user(self):
request = self.factory.get(self.url + 'testuser')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request, 'testuser')
self.assertEqual(
response.data,
{
'first_name': 'Test',
'last_name': 'User',
'username': 'testuser',
'is_active': True,
'is_superuser': False,
'email': '<EMAIL>',
'date_joined': '2015-01-01 00:00:00',
'last_login': '',
'pk': self.tenant_user1.pk
}
)
def test_get_user_by_username_tenant_user_another_username(self):
request = self.factory.get(self.url + 'another_user')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request, 'another_user')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(
response.data['detail'],
'You do not have permission to fetch users other than yourself.'
)
def test_get_user_by_username_if_username_does_not_exist_sp_superuser(self):
with schema_context(get_public_schema_name()):
request = self.factory.get(self.url + 'testuser')
force_authenticate(request, user=self.user2)
response = self.view(request, 'testuser')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
def test_get_user_by_username_if_username_does_not_exist_sp_user(self):
with schema_context(get_public_schema_name()):
request = self.factory.get(self.url + 'testuser')
force_authenticate(request, user=self.user1)
response = self.view(request, 'testuser')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(
response.data['detail'],
'You do not have permission to fetch users other than yourself.'
)
def test_get_user_by_username_if_username_does_not_exist_tnant_sprusr(self):
request = self.factory.get(self.url + 'Alan_Ford')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request, 'Alan_Ford')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
def test_get_user_by_username_if_username_does_not_exist_tenant_user(self):
request = self.factory.get(self.url + 'Alan_Ford')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request, 'Alan_Ford')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(
response.data['detail'],
'You do not have permission to fetch users other than yourself.'
)
def test_put_user_sp_superuser(self):
with schema_context(get_public_schema_name()):
data = {
'pk': self.user1.pk,
'username': 'testuser2',
'first_name': 'Testing',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
user = CustUser.objects.get(id=self.user1.id)
self.assertEqual(user.username, 'testuser2')
self.assertEqual(user.first_name, 'Testing')
self.assertEqual(user.last_name, 'Newuser')
self.assertEqual(user.email, '<EMAIL>')
self.assertTrue(user.is_superuser)
self.assertTrue(user.is_active)
def test_put_user_sp_user(self):
with schema_context(get_public_schema_name()):
data = {
'pk': self.user1.pk,
'username': 'testuser2',
'first_name': 'Testing',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
user = CustUser.objects.get(id=self.user1.id)
self.assertEqual(user.username, 'Alan_Ford')
self.assertEqual(user.first_name, 'Alan')
self.assertEqual(user.last_name, 'Ford')
self.assertEqual(user.email, '<EMAIL>')
self.assertFalse(user.is_superuser)
self.assertTrue(user.is_active)
def test_put_user_tenant_superuser(self):
data = {
'pk': self.tenant_user1.pk,
'username': 'testuser2',
'first_name': 'Testing',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
user = CustUser.objects.get(id=self.tenant_user1.pk)
self.assertEqual(user.username, 'testuser2')
self.assertEqual(user.first_name, 'Testing')
self.assertEqual(user.last_name, 'Newuser')
self.assertEqual(user.email, '<EMAIL>')
self.assertTrue(user.is_superuser)
self.assertTrue(user.is_active)
def test_put_user_tenant_user(self):
data = {
'pk': self.tenant_user1.pk,
'username': 'testuser2',
'first_name': 'Testing',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
user = CustUser.objects.get(id=self.tenant_user1.pk)
self.assertEqual(user.username, 'testuser')
self.assertEqual(user.first_name, 'Test')
self.assertEqual(user.last_name, 'User')
self.assertEqual(user.email, '<EMAIL>')
self.assertFalse(user.is_superuser)
self.assertTrue(user.is_active)
def test_put_user_with_already_existing_name_sp_superuser(self):
with schema_context(get_public_schema_name()):
data = {
'pk': self.user1.pk,
'username': 'Number1',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'],
'User with this username already exists.'
)
def test_put_user_with_already_existing_name_sp_user(self):
with schema_context(get_public_schema_name()):
data = {
'pk': self.user1.pk,
'username': 'Number1',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
def test_put_user_with_already_existing_name_tenant_superuser(self):
data = {
'pk': self.tenant_user1.pk,
'username': 'another_user',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'], 'User with this username already exists.'
)
def test_put_user_with_already_existing_name_tenant_user(self):
data = {
'pk': self.tenant_user1.pk,
'username': 'another_user',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
def test_put_nonexisting_user_sp_superuser(self):
with schema_context(get_public_schema_name()):
data = {
'pk': 999,
'username': 'testuser2',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
def test_put_nonexisting_user_sp_user(self):
with schema_context(get_public_schema_name()):
data = {
'pk': 999,
'username': 'testuser2',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
def test_put_nonexisting_user_tenant_superuser(self):
data = {
'pk': 999,
'username': 'testuser2',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
def test_put_nonexisting_user_tenant_user(self):
data = {
'pk': 999,
'username': 'testuser2',
'first_name': 'Test',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
def test_put_user_missing_data_key_sp_superuser(self):
with schema_context(get_public_schema_name()):
data = {
'pk': self.user1.pk,
'username': 'testuser2',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'], 'Missing data key: first_name'
)
user = CustUser.objects.get(id=self.user1.id)
self.assertEqual(user.username, 'Alan_Ford')
self.assertEqual(user.first_name, 'Alan')
self.assertEqual(user.last_name, 'Ford')
self.assertEqual(user.email, '<EMAIL>')
self.assertFalse(user.is_superuser)
self.assertTrue(user.is_active)
def test_put_user_missing_data_key_sp_user(self):
with schema_context(get_public_schema_name()):
data = {
'pk': self.user1.pk,
'username': 'testuser2',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(
self.url, content, content_type=content_type
)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
user = CustUser.objects.get(id=self.user1.id)
self.assertEqual(user.username, 'Alan_Ford')
self.assertEqual(user.first_name, 'Alan')
self.assertEqual(user.last_name, 'Ford')
self.assertEqual(user.email, '<EMAIL>')
self.assertFalse(user.is_superuser)
self.assertTrue(user.is_active)
def test_put_user_missing_data_key_tenant_superuser(self):
data = {
'pk': self.tenant_user1.pk,
'username': 'testuser2',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'], 'Missing data key: first_name'
)
user = CustUser.objects.get(id=self.tenant_user1.id)
self.assertEqual(user.username, 'testuser')
self.assertEqual(user.first_name, 'Test')
self.assertEqual(user.last_name, 'User')
self.assertEqual(user.email, '<EMAIL>')
self.assertFalse(user.is_superuser)
self.assertTrue(user.is_active)
def test_put_user_missing_data_key_tenant_user(self):
data = {
'pk': self.tenant_user1.pk,
'username': 'testuser2',
'last_name': 'Newuser',
'email': '<EMAIL>',
'is_superuser': False,
'is_active': True
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change users.'
)
user = CustUser.objects.get(id=self.tenant_user1.id)
self.assertEqual(user.username, 'testuser')
self.assertEqual(user.first_name, 'Test')
self.assertEqual(user.last_name, 'User')
self.assertEqual(user.email, '<EMAIL>')
self.assertFalse(user.is_superuser)
self.assertTrue(user.is_active)
def test_post_user_sp_superuser(self):
with schema_context(get_public_schema_name()):
self.assertEqual(CustUser.objects.all().count(), 2)
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(CustUser.objects.all().count(), 3)
user = CustUser.objects.get(username='newuser')
self.assertEqual(user.username, 'newuser')
self.assertEqual(user.first_name, 'New')
self.assertEqual(user.last_name, 'User')
self.assertEqual(user.email, '<EMAIL>')
self.assertTrue(user.is_superuser)
self.assertTrue(user.is_active)
def test_post_user_sp_user(self):
with schema_context(get_public_schema_name()):
self.assertEqual(CustUser.objects.all().count(), 2)
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
self.assertRaises(
CustUser.DoesNotExist,
CustUser.objects.get,
username='newuser'
)
def test_post_user_tenant_superuser(self):
self.assertEqual(CustUser.objects.all().count(), 2)
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(CustUser.objects.all().count(), 3)
user = CustUser.objects.get(username='newuser')
self.assertEqual(user.username, 'newuser')
self.assertEqual(user.first_name, 'New')
self.assertEqual(user.last_name, 'User')
self.assertEqual(user.email, '<EMAIL>')
self.assertTrue(user.is_superuser)
self.assertTrue(user.is_active)
def test_post_user_tenant_user(self):
self.assertEqual(CustUser.objects.all().count(), 2)
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'], 'You do not have permission to add users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
self.assertRaises(
CustUser.DoesNotExist,
CustUser.objects.get,
username='newuser'
)
def test_post_user_with_already_existing_username_sp_superuser(self):
with schema_context(get_public_schema_name()):
data = {
'username': 'Number1',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'],
'User with this username already exists.'
)
def test_post_user_with_already_existing_username_sp_user(self):
with schema_context(get_public_schema_name()):
data = {
'username': 'Number1',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(CustUser.objects.all().count(), 2)
self.assertEqual(
response.data['detail'],
'You do not have permission to add users.'
)
def test_post_user_with_already_existing_username_tenant_superuser(self):
data = {
'username': 'testuser',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'], 'User with this username already exists.'
)
def test_post_user_with_already_existing_username_tenant_user(self):
data = {
'username': 'testuser',
'first_name': 'New',
'last_name': 'User',
'email': '<EMAIL>',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'], 'You do not have permission to add users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_post_user_with_missing_data_key_sp_superuser(self):
with schema_context(get_public_schema_name()):
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data['detail'], 'Missing data key: email')
self.assertEqual(CustUser.objects.all().count(), 2)
def test_post_user_with_missing_data_key_sp_user(self):
with schema_context(get_public_schema_name()):
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_post_user_with_missing_data_key_tenant_superuser(self):
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data['detail'], 'Missing data key: email')
self.assertEqual(CustUser.objects.all().count(), 2)
def test_post_user_with_missing_data_key_tenant_user(self):
data = {
'username': 'newuser',
'first_name': 'New',
'last_name': 'User',
'is_superuser': True,
'is_active': True,
'password': '<PASSWORD>',
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'], 'You do not have permission to add users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_sp_superuser(self):
with schema_context(get_public_schema_name()):
request = self.factory.delete(self.url + 'Alan_Ford')
force_authenticate(request, user=self.user2)
response = self.view(request, 'Alan_Ford')
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(CustUser.objects.all().count(), 1)
self.assertRaises(
CustUser.DoesNotExist,
CustUser.objects.get,
username='Alan_Ford'
)
def test_delete_yourself_sp_superuser(self):
with schema_context(get_public_schema_name()):
request = self.factory.delete(self.url + 'Number1')
force_authenticate(request, user=self.user2)
response = self.view(request, 'Number1')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'], 'You cannot delete yourself.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_sp_user(self):
with schema_context(get_public_schema_name()):
request = self.factory.delete(self.url + 'Alan_Ford')
force_authenticate(request, user=self.user1)
response = self.view(request, 'Alan_Ford')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to delete users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_tenant_superuser(self):
request = self.factory.delete(self.url + 'testuser')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request, 'testuser')
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(CustUser.objects.all().count(), 1)
self.assertRaises(
CustUser.DoesNotExist,
CustUser.objects.get,
username='testuser'
)
def test_delete_yourself_tenant_superuser(self):
request = self.factory.delete(self.url + 'another_user')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request, 'another_user')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data['detail'], 'You cannot delete yourself.')
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_tenant_user(self):
request = self.factory.delete(self.url + 'testuser')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request, 'testuser')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to delete users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_nonexisting_user_sp_superuser(self):
with schema_context(get_public_schema_name()):
request = self.factory.delete(self.url + 'nonexisting')
force_authenticate(request, user=self.user2)
response = self.view(request, 'nonexisting')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_nonexisting_user_sp_user(self):
with schema_context(get_public_schema_name()):
request = self.factory.delete(self.url + 'nonexisting')
force_authenticate(request, user=self.user1)
response = self.view(request, 'nonexisting')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to delete users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_nonexisting_user_tenant_superuser(self):
request = self.factory.delete(self.url + 'nonexisting')
force_authenticate(request, user=self.tenant_user2)
response = self.view(request, 'nonexisting')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_nonexisting_user_tenant_user(self):
request = self.factory.delete(self.url + 'nonexisting')
force_authenticate(request, user=self.tenant_user1)
response = self.view(request, 'nonexisting')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to delete users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_without_specifying_username_sp_superuser(self):
with schema_context(get_public_schema_name()):
request = self.factory.delete(self.url)
force_authenticate(request, user=self.user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'], 'Username should be specified.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_without_specifying_username_sp_user(self):
with schema_context(get_public_schema_name()):
request = self.factory.delete(self.url)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to delete users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_without_specifying_username_tenant_superuser(self):
request = self.factory.delete(self.url)
force_authenticate(request, user=self.tenant_user2)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data['detail'], 'Username should be specified.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
def test_delete_user_without_specifying_username_tenant_user(self):
request = self.factory.delete(self.url)
force_authenticate(request, user=self.tenant_user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to delete users.'
)
self.assertEqual(CustUser.objects.all().count(), 2)
class GetUserProfileForUsernameAPIViewTests(TenantTestCase):
def setUp(self):
self.factory = TenantRequestFactory(self.tenant)
self.view = views.GetUserprofileForUsername.as_view()
self.url = '/api/v2/internal/userprofile/'
self.user = CustUser.objects.create(username='testuser')
self.superuser = CustUser.objects.create(
username='poem', is_superuser=True
)
user1 = CustUser.objects.create_user(
username='username1',
first_name='First',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
CustUser.objects.create_user(
username='username2',
first_name='Second',
last_name='user',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
self.gm = poem_models.GroupOfMetrics.objects.create(
name='GROUP-metrics'
)
poem_models.GroupOfMetrics.objects.create(name='GROUP2-metrics')
self.ga = poem_models.GroupOfAggregations.objects.create(
name='GROUP-aggregations'
)
poem_models.GroupOfAggregations.objects.create(
name='GROUP2-aggregations'
)
self.gmp = poem_models.GroupOfMetricProfiles.objects.create(
name='GROUP-metricprofiles'
)
self.gtp = poem_models.GroupOfThresholdsProfiles.objects.create(
name='GROUP-thresholds'
)
poem_models.GroupOfThresholdsProfiles.objects.create(
name='GROUP2-thresholds'
)
self.userprofile = poem_models.UserProfile.objects.create(
user=user1,
subject='bla',
displayname='First_User',
egiid='blablabla'
)
self.userprofile.groupsofmetrics.add(self.gm)
self.userprofile.groupsofaggregations.add(self.ga)
self.userprofile.groupsofmetricprofiles.add(self.gmp)
self.userprofile.groupsofthresholdsprofiles.add(self.gtp)
def test_get_user_profile_for_given_username_superuser(self):
request = self.factory.get(self.url + 'username1')
force_authenticate(request, user=self.superuser)
response = self.view(request, 'username1')
self.assertEqual(
response.data,
OrderedDict([
('subject', 'bla'),
('egiid', 'blablabla'),
('displayname', 'First_User')
])
)
def test_get_user_profile_for_given_username_user(self):
request = self.factory.get(self.url + 'username1')
force_authenticate(request, user=self.user)
response = self.view(request, 'username1')
self.assertEqual(
response.data,
OrderedDict([
('subject', 'bla'),
('egiid', 'blablabla'),
('displayname', 'First_User')
])
)
def test_get_user_profile_if_username_does_not_exist_superuser(self):
request = self.factory.get(self.url + 'nonexisting')
force_authenticate(request, user=self.superuser)
response = self.view(request, 'nonexisting')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
def test_get_user_profile_if_username_does_not_exist_user(self):
request = self.factory.get(self.url + 'nonexisting')
force_authenticate(request, user=self.user)
response = self.view(request, 'nonexisting')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
def test_get_user_profile_if_user_profile_does_not_exist_superuser(self):
request = self.factory.get(self.url + 'testuser')
force_authenticate(request, user=self.superuser)
response = self.view(request, 'testuser')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'User profile does not exist.'
)
def test_get_user_profile_if_user_profile_does_not_exist_user(self):
request = self.factory.get(self.url + 'testuser')
force_authenticate(request, user=self.user)
response = self.view(request, 'testuser')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'User profile does not exist.'
)
def test_put_userprofile_superuser(self):
self.assertEqual(self.userprofile.groupsofmetrics.count(), 1)
self.assertEqual(self.userprofile.groupsofmetricprofiles.count(), 1)
self.assertEqual(self.userprofile.groupsofaggregations.count(), 1)
self.assertEqual(self.userprofile.groupsofthresholdsprofiles.count(), 1)
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'Username_1')
self.assertEqual(userprofile.egiid, 'newegiid')
self.assertEqual(userprofile.subject, 'newsubject')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP2-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 2)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP2-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP2-thresholds'
).exists()
)
def test_put_userprofile_user(self):
self.assertEqual(self.userprofile.groupsofmetrics.count(), 1)
self.assertEqual(self.userprofile.groupsofmetricprofiles.count(), 1)
self.assertEqual(self.userprofile.groupsofaggregations.count(), 1)
self.assertEqual(self.userprofile.groupsofthresholdsprofiles.count(), 1)
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_user_superuser(self):
data = {
'username': 'nonexisting',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
def test_put_userprofile_nonexisting_user_user(self):
data = {
'username': 'nonexisting',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
def test_put_userprofile_nonexisting_userprofile_superuser(self):
data = {
'username': 'username2',
'displayname': 'Username_2',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'User profile does not exist.'
)
def test_put_userprofile_nonexisting_userprofile_user(self):
data = {
'username': 'username2',
'displayname': 'Username_2',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
def test_put_userprofile_nonexisting_group_of_aggr_superuser(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP3-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'Group of aggregations does not exist.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_group_of_aggr_user(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP3-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_group_of_metrics_superuser(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP3-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'Group of metrics does not exist.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_group_of_metrics_user(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP3-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_group_of_metric_profiles_suprusr(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP2-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'Group of metric profiles does not exist.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_group_of_metric_profiles_user(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP2-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP2-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_group_of_thresh_profiles_suprusr(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP3-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'],
'Group of thresholds profiles does not exist.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_nonexisting_group_of_thresh_profiles_user(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'subject': 'newsubject',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP3-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_missing_data_key_superuser(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data['detail'], 'Missing data key: subject')
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_put_userprofile_missing_data_key_user(self):
data = {
'username': 'username1',
'displayname': 'Username_1',
'egiid': 'newegiid',
'groupsofaggregations': ['GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics', 'GROUP2-metrics'],
'groupsofmetricprofiles': ['GROUP-metricprofiles'],
'groupsofthresholdsprofiles': ['GROUP-thresholds']
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change user profiles.'
)
userprofile = poem_models.UserProfile.objects.get(
id=self.userprofile.id
)
self.assertEqual(userprofile.displayname, 'First_User')
self.assertEqual(userprofile.egiid, 'blablabla')
self.assertEqual(userprofile.subject, 'bla')
self.assertEqual(userprofile.groupsofaggregations.count(), 1)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofmetricprofiles.filter(
name='GROUP-metricprofiles'
).exists()
)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 1)
self.assertTrue(
userprofile.groupsofthresholdsprofiles.filter(
name='GROUP-thresholds'
).exists()
)
def test_post_userprofile_superuser(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 2)
userprofile = poem_models.UserProfile.objects.get(user=user)
self.assertEqual(userprofile.displayname, 'Second_User')
self.assertEqual(userprofile.egiid, 'bla')
self.assertEqual(userprofile.subject, 'secondsubject')
self.assertEqual(userprofile.groupsofaggregations.count(), 2)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP-aggregations'
).exists()
)
self.assertTrue(
userprofile.groupsofaggregations.filter(
name='GROUP2-aggregations'
).exists()
)
self.assertEqual(userprofile.groupsofmetrics.count(), 1)
self.assertTrue(
userprofile.groupsofmetrics.filter(
name='GROUP-metrics'
).exists()
)
self.assertEqual(userprofile.groupsofmetricprofiles.count(), 0)
self.assertEqual(userprofile.groupsofthresholdsprofiles.count(), 0)
def test_post_userprofile_user(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add user profiles.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_user_superuser(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data['detail'], 'User does not exist.')
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
def test_post_userprofile_nonexisting_user_user(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add user profiles.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
def test_post_userprofile_nonexisting_groupofaggr_superuser(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP3-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'Group of aggregations does not exist.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_groupofaggr_user(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP3-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add user profiles.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_groupofmetrics_superuser(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP3-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'], 'Group of metrics does not exist.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_groupofmetrics_user(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP2-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add user profiles.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_groupofmetricprofiles_supruser(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': ['GROUP1-metricprofiles']
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'],
'Group of metric profiles does not exist.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_groupofmetricprofiles_user(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': ['GROUP1-metricprofiles']
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add user profiles.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_groupofthreshprofiles_superuser(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': ['GROUP3-thresholds'],
'groupsofmetricprofiles': ['GROUP-metricprofiles']
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(
response.data['detail'],
'Group of thresholds profiles does not exist.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_nonexisting_groupofthreshprofiles_user(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'egiid': 'bla',
'groupsofaggregations': ['GROUP-aggregations',
'GROUP2-aggregations'],
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': ['GROUP3-thresholds'],
'groupsofmetricprofiles': ['GROUP-metricprofiles']
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add user profiles.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_missing_data_key_superuser(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.superuser)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data['detail'], 'Missing data key: egiid')
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
def test_post_userprofile_missing_data_key_user(self):
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
user = CustUser.objects.create_user(
username='username3',
first_name='Second',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
data = {
'username': 'username3',
'displayname': 'Second_User',
'subject': 'secondsubject',
'groupsofmetrics': ['GROUP-metrics'],
'groupsofthresholdsprofiles': [],
'groupsofmetricprofiles': []
}
request = self.factory.post(self.url, data, format='json')
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to add user profiles.'
)
self.assertEqual(poem_models.UserProfile.objects.all().count(), 1)
self.assertRaises(
poem_models.UserProfile.DoesNotExist,
poem_models.UserProfile.objects.get,
user=user
)
class ListGroupsForGivenUserAPIViewTests(TenantTestCase):
def setUp(self):
self.factory = TenantRequestFactory(self.tenant)
self.view = views.ListGroupsForGivenUser.as_view()
self.url = '/api/v2/internal/usergroups/'
self.user = CustUser.objects.create(username='testuser')
user1 = CustUser.objects.create_user(
username='username1',
first_name='First',
last_name='User',
email='<EMAIL>',
is_active=True,
is_superuser=False
)
gm = poem_models.GroupOfMetrics.objects.create(name='GROUP-metrics')
poem_models.GroupOfMetrics.objects.create(name='GROUP2-metrics')
ga = poem_models.GroupOfAggregations.objects.create(
name='GROUP-aggregations'
)
gmp = poem_models.GroupOfMetricProfiles.objects.create(
name='GROUP-metricprofiles'
)
gtp = poem_models.GroupOfThresholdsProfiles.objects.create(
name='GROUP-thresholds'
)
poem_models.GroupOfReports.objects.create(name='GROUP1-reports')
gr = poem_models.GroupOfReports.objects.create(name='GROUP2-reports')
userprofile = poem_models.UserProfile.objects.create(
user=user1
)
userprofile.groupsofmetrics.add(gm)
userprofile.groupsofaggregations.add(ga)
userprofile.groupsofmetricprofiles.add(gmp)
userprofile.groupsofthresholdsprofiles.add(gtp)
userprofile.groupsofreports.add(gr)
def test_get_groups_for_given_user(self):
request = self.factory.get(self.url + 'username1')
force_authenticate(request, user=self.user)
response = self.view(request, 'username1')
self.assertEqual(
response.data,
{
'result': {
'aggregations': ['GROUP-aggregations'],
'metrics': ['GROUP-metrics'],
'metricprofiles': ['GROUP-metricprofiles'],
'reports': ['GROUP2-reports'],
'thresholdsprofiles': ['GROUP-thresholds']
}
}
)
def test_get_all_groups(self):
request = self.factory.get(self.url)
force_authenticate(request, user=self.user)
response = self.view(request)
self.assertEqual(
response.data,
{
'result': {
'aggregations': ['GROUP-aggregations'],
'metrics': ['GROUP-metrics', 'GROUP2-metrics'],
'metricprofiles': ['GROUP-metricprofiles'],
'reports': ['GROUP1-reports', 'GROUP2-reports'],
'thresholdsprofiles': ['GROUP-thresholds']
}
}
)
class ChangePasswordTests(TenantTestCase):
def setUp(self):
self.factory = TenantRequestFactory(self.tenant)
self.view = views.ChangePassword.as_view()
self.url = '/api/v2/internal/change_password'
self.user1 = CustUser.objects.create_user(
username='testuser',
first_name='Test',
last_name='User',
email='<EMAIL>',
date_joined=datetime.datetime(2015, 1, 1, 0, 0, 0)
)
self.user2 = CustUser.objects.create_user(
username='anotheruser',
first_name='Another',
last_name='Test',
email='<EMAIL>',
date_joined=datetime.datetime(2015, 1, 1, 0, 0, 0)
)
self.user3 = CustUser.objects.create_user(
username='testuser3',
first_name='John',
last_name='Doe',
email='<EMAIL>',
date_joined=datetime.datetime(2015, 1, 1, 0, 0, 0),
is_superuser=True
)
def test_change_password(self):
data = {
'username': 'testuser',
'new_password': '<PASSWORD>'
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
user = CustUser.objects.get(username=self.user1.username)
self.assertTrue(user.check_password('<PASSWORD>'))
def test_try_change_password_for_different_user(self):
data = {
'username': 'anotheruser',
'new_password': '<PASSWORD>-cool-passwd'
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change password for another user.'
)
def test_try_change_password_for_different_user_superuser(self):
data = {
'username': 'anotheruser',
'new_password': '<PASSWORD>'
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user3)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change password for another user.'
)
def test_change_password_for_nonexisting_user(self):
data = {
'username': 'nonexisting',
'new_password': '<PASSWORD>'
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change password for another user.'
)
def test_change_password_for_nonexisting_user_superuser(self):
data = {
'username': 'nonexisting',
'new_password': '<PASSWORD>'
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user3)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(
response.data['detail'],
'You do not have permission to change password for another user.'
)
def test_change_password_missing_data_key(self):
data = {
'new_password': '<PASSWORD>'
}
content, content_type = encode_data(data)
request = self.factory.put(self.url, content, content_type=content_type)
force_authenticate(request, user=self.user1)
response = self.view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data['detail'], 'Missing data key: username')
|
# -*- coding: utf-8 -*-
from os.path import join
import pytest
import matplotlib.pyplot as plt
from numpy import pi
from pyleecan.Classes.Frame import Frame
from pyleecan.Classes.LamHole import LamHole
from pyleecan.Classes.LamSlotWind import LamSlotWind
from pyleecan.Classes.MachineIPMSM import MachineIPMSM
from pyleecan.Classes.Magnet import Magnet
from pyleecan.Classes.Shaft import Shaft
from pyleecan.Classes.HoleM51 import HoleM51
from Tests import save_plot_path as save_path
"""unittest for Lamination with Hole 51 plot"""
@pytest.fixture
def machine():
"""Run at the begining of every test to setup the machine"""
plt.close("all")
test_obj = MachineIPMSM()
test_obj.rotor = LamHole(
Rint=45e-3 / 2, Rext=81.5e-3, is_stator=False, is_internal=True, L1=0.9
)
test_obj.rotor.hole = list()
test_obj.rotor.hole.append(
HoleM51(
Zh=8,
W0=0.016,
W1=pi / 6,
W2=0.004,
W3=0.01,
W4=0.002,
W5=0.01,
W6=0.002,
W7=0.01,
H0=0.01096,
H1=0.0015,
H2=0.0055,
)
)
test_obj.shaft = Shaft(Drsh=test_obj.rotor.Rint * 2, Lshaft=1.2)
test_obj.stator = LamSlotWind(
Rint=0.09, Rext=0.12, is_internal=False, is_stator=True, L1=0.9, slot=None
)
test_obj.frame = Frame(Rint=0.12, Rext=0.12, Lfra=0.7)
return test_obj
def test_Lam_Hole_51_012(machine):
"""Test machine plot hole 51 with all magnets
"""
machine.rotor.hole[0].magnet_0 = Magnet()
machine.rotor.hole[0].magnet_1 = Magnet()
machine.rotor.hole[0].magnet_2 = Magnet()
machine.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_1-Machine_012.png"))
# Rotor + 2 for stator + 0 for frame + 1 for shaft
assert len(fig.axes[0].patches) == 61
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_1-Rotor_012.png"))
# 2 for lam + 7*8 for holes
assert len(fig.axes[0].patches) == 58
def test_Lam_Hole_51_N12(machine):
"""Test machine plot hole 51 with no magnet_0
"""
machine.rotor.hole[0].magnet_0 = None
machine.rotor.hole[0].magnet_1 = Magnet()
machine.rotor.hole[0].magnet_2 = Magnet()
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_2-Rotor_N12.png"))
# 2 for lam + 5*8 for holes
assert len(fig.axes[0].patches) == 42
def test_Lam_Hole_51_0N2(machine):
"""Test machine plot hole 51 with no magnet_1
"""
machine.rotor.hole[0].magnet_0 = Magnet()
machine.rotor.hole[0].magnet_1 = None
machine.rotor.hole[0].magnet_2 = Magnet()
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_3-Rotor_0N2.png"))
# 2 for lam + 5*8 for holes
assert len(fig.axes[0].patches) == 42
def test_Lam_Hole_51_NN2(machine):
"""Test machine plot hole 51 with no magnet_0 and no magnet_1
"""
machine.rotor.hole[0].magnet_0 = None
machine.rotor.hole[0].magnet_1 = None
machine.rotor.hole[0].magnet_2 = Magnet()
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_4-Rotor_NN2.png"))
# 2 for lam + 3*8 for holes
assert len(fig.axes[0].patches) == 26
def test_Lam_Hole_51_01N(machine):
"""Test machine plot hole 51 with no magnet_2
"""
machine.rotor.hole[0].magnet_0 = Magnet()
machine.rotor.hole[0].magnet_1 = Magnet()
machine.rotor.hole[0].magnet_2 = None
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_5-Rotor_01N.png"))
# 2 for lam + 5*8 for holes
assert len(fig.axes[0].patches) == 42
def test_Lam_Hole_51_N1N(machine):
"""Test machine plot hole 51 with no magnet_0 and no magnet_2
"""
machine.rotor.hole[0].magnet_0 = None
machine.rotor.hole[0].magnet_1 = Magnet()
machine.rotor.hole[0].magnet_2 = None
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_6-Rotor_N1N.png"))
# 2 for lam + 3*8 for holes
assert len(fig.axes[0].patches) == 26
def test_Lam_Hole_51_0NN(machine):
"""Test machine plot hole 51 with no magnet_1 and no magnet_2
"""
machine.rotor.hole[0].magnet_0 = Magnet()
machine.rotor.hole[0].magnet_1 = None
machine.rotor.hole[0].magnet_2 = None
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_7-Rotor_0NN.png"))
# 2 for lam + 3*8 for holes
assert len(fig.axes[0].patches) == 26
def test_Lam_Hole_51_NNN(machine):
"""Test machine plot hole 51 with no magnet
"""
machine.rotor.hole[0].magnet_0 = None
machine.rotor.hole[0].magnet_1 = None
machine.rotor.hole[0].magnet_2 = None
machine.rotor.plot()
fig = plt.gcf()
fig.savefig(join(save_path, "test_Lam_Hole_s51_8-Rotor_NNN.png"))
# 2 for lam + 1*8 for holes
assert len(fig.axes[0].patches) == 10
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.