Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# 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 common.tools.object_factory.OpticalLink import order_dict
import logging
from sqlalchemy.types import PickleType , TypeDecorator ,Integer
class SlotType(TypeDecorator):
impl = Integer
def process_bind_param(self, value, dialect):
if value is not None:
logging.info(f"before ordering {value} ")
value =order_dict(value)
logging.info(f"after ordering {value} ")
bin_num="0b"
for i,(key,val) in enumerate(value.items()):
bin_num =bin_num + f"{val}"
logging.info(f"after ordering bin_num {bin_num} ")
int_num = int(bin_num,2)
return int_num
def process_result_value(self, value, dialect):
if value is not None:
slot= dict()
bin_num = bin(value)
sliced_num=bin_num[2:]
for i in range(len(sliced_num)):
slot[str(i+1)]=int(sliced_num[i])
return slot
class C_Slot (SlotType):
start_point=0
def process_result_value(self, value, dialect):
if value is not None:
slot= dict()
bin_num = bin(value)
sliced_num=bin_num[2:]
if (len(sliced_num) != 20) :
for i in range(0,20 - len(sliced_num)):
sliced_num='0'+sliced_num
logging.info(f"sliced_num {sliced_num}")
for i in range(len(sliced_num)):
slot[str(self.start_point+i+1)]=int(sliced_num[i])
return slot
class L_Slot (SlotType):
start_point=100
def process_result_value(self, value, dialect):
if value is not None:
slot= dict()
bin_num = bin(value)
sliced_num=bin_num[2:]
if (len(sliced_num) != 20) :
for i in range(0,20 - len(sliced_num)):
sliced_num='0'+sliced_num
for i in range(len(sliced_num)):
slot[str(self.start_point+i+1)]=int(sliced_num[i])
return slot
class S_Slot (SlotType):
start_point=500
def process_result_value(self, value, dialect):
if value is not None:
slot= dict()
bin_num = bin(value)
sliced_num=bin_num[2:]
if (len(sliced_num) != 20) :
for i in range(0,20 - len(sliced_num)):
sliced_num='0'+sliced_num
for i in range(len(sliced_num)):
slot[str(self.start_point+i+1)]=int(sliced_num[i])
return slot