class TestShallowCompression(CompressionTestCaseMixin, unittest.TestCase): def setUp(self): self.comp = Compression(False) def test_parse_marker_data(self): self.assert_parse_market_data('abcdefg', Marker(4, 3), Element([Element('abcd', 1)], 3), 'efg') def test_parse_marker(self): self.assert_parse_marker('(3x51)abcd', Element([Element('abc', 1)], 51), 'd') self.assert_parse_marker('(0x51)', Element([Element('', 1)], 51), '') self.assert_parse_marker('(2x51)ab', Element([Element('ab', 1)], 51), '') def test_parse(self): text = 'abcd(8x15)(10x11)efg(3x3)hijklm' expected = Element([ Element('abcd', 1), Element([Element('(10x11)e', 1)], 15), Element('fg', 1), Element([Element('hij', 1)], 3), Element('klm', 1) ], repeat=1) self.assertEqual(self.comp.parse(text), expected) def test_decompress(self): self.assert_decompress('ADVENT', 'ADVENT') self.assert_decompress('A(1x5)BC', 'ABBBBBC') self.assert_decompress('(3x3)XYZ', 'XYZXYZXYZ') self.assert_decompress('A(2x2)BCD(2x2)EFG', 'ABCBCDEFEFG') self.assert_decompress('(6x1)(1x3)A', '(1x3)A') self.assert_decompress('X(8x2)(3x3)ABCY', 'X(3x3)ABC(3x3)ABCY')
def get_entry_from_info(self, file_info): info_dict = {} uuid = file_info[0] file_name = Compression.get_filename_with_extension( file_info[1]).strip() # Special case in which the filename in the manifest is saved with the # uuid/file if "/" in file_name: index = file_name.index("/") + 1 file_name = file_name[index:] info_dict[self.headers[1]] = file_name # add filename compressed if the file is compressed if Compression.is_file_compressed(file_info[1]): info_dict["name_compressed"] = file_info[1].strip() for i in range(2, len(self.headers)): info_dict[self.headers[i]] = file_info[i].strip() return uuid, info_dict
def check_previous_folders(self): curr_dir = os.getcwd() os.chdir(self.config.downloadsDir) found_old_dir = False directories = get_directories_in_dir() dir_dict, dir_key = self.manifest.get_dirname_dict() dir_present = [value[dir_key] for key, value in dir_dict.viewitems()] for directory in directories: # check if is not saved in the CustomManifest if directory not in dir_present: # check if a manifest is present in the directory files = get_files_in_dir(directory) manifest_list = [man for man in files if man.__contains__("manifest")] other_files_list = [others for others in files if not others.__contains__("manifest")] if len(manifest_list) > 0: # there's at least a manifest, so let's try to see if the # directory can be added to the list of dirs by seeing if # one of the files is in the manifest file_found = False for manifest in manifest_list: gdc_man = GDCManifest(os.path.join(directory, manifest)) for uuid, info in gdc_man.get_list_of_files(): filename = info[gdc_man.get_name_header()] filename_no_ext = Compression.get_filename(filename) if filename in other_files_list \ and filename_no_ext in directory: file_found = True uuid_found = uuid meta_found = directory.replace( "_" + filename_no_ext, "") new_info = info new_info[ gdc_man.get_metadata_header()] = meta_found self.manifest.add_dictionary( {uuid_found: new_info}) logging.info("Added dir {0}".format(directory)) break if file_found: found_old_dir = True break os.chdir(curr_dir) if found_old_dir: self.manifest.serialize_manifest()
class TestDeepCompression(CompressionTestCaseMixin, unittest.TestCase): def setUp(self): self.comp = Compression(True) def test_parse_marker_data(self): text = '(2x2)BCD(2x2)EFG' marker = Marker(len(text) - 1, 3) element = Element([ Element([Element('BC', 1)], 2), Element('D', 1), Element([Element('EF', 1)], 2) ], repeat=3) self.assert_parse_market_data(text, marker, element, 'G') def test_parse_marker(self): element = Element([Element('abc', 1)], 51) self.assert_parse_marker('(3x51)abcd', element, 'd') self.assert_parse_marker('(0x51)', Element([], 51), '') element = Element([Element('ab', 1)], 51) self.assert_parse_marker('(2x51)ab', element, '') def test_parse(self): text = 'abcd(7x15)(1x11)efg(3x3)hijklm' expected = Element([ Element('abcd', 1), Element([Element([Element('e', 1)], 11)], 15), Element('fg', 1), Element([Element('hij', 1)], 3), Element('klm', 1) ], repeat=1) self.assertEqual(self.comp.parse(text), expected) def test_decompress(self): self.assert_decompress('ADVENT', 'ADVENT') self.assert_decompress('A(1x5)BC', 'ABBBBBC') self.assert_decompress('(3x3)XYZ', 'XYZXYZXYZ') self.assert_decompress('A(2x2)BCD(2x2)EFG', 'ABCBCDEFEFG') self.assert_decompress('(6x1)(1x3)A', 'AAA') self.assert_decompress('X(8x2)(3x3)ABCY', 'XABCABCABCABCABCABCY')
def main(): in_data = input() in_data = list(map(int, in_data.split())) matrix = [] for i in range(in_data[1]): matrix.append(list(map(int, input().split()))) mx1 = Matrix(matrix) Search = Compression(mx1) Search.find_minima(in_data[0], in_data[3]) for i in Search.get_best_solution(): for j in i: print(j, file=sys.stderr, end=' ') print(file=sys.stderr) print(Search.get_best_distance())
def run(self): '''Fonction executee quand l'utilisateur clique sur "Run".''' self.stopped = False # Creation de l'echantillon en testant la validite des parametres # fournis par l'utilisateur try: rs = RockSample(self.L.get_val(), self.C.get_val(), self.leq0.get_val(), self.Rl.get_val(), self.A0.get_val(), self.Ka.get_val(), self.E0.get_val(), self.Ke.get_val(), self.F0cr.get_val(), self.D.get_val()) #rs.debug = True print(rs) cpr = Compression(rs, self.F0x.get_val(), self.Kbc.get_val(), self.d0.get_val(), self.delt_d.get_val(), self.max_comp.get_val()) delta_comp_rate = self.delta_comp.get_val() except: # si une erreur dans les parametres est detectee, soulever # l'erreur pour interrompre le programme raise def draw_sample(): "fonction d'affichage de l'echantillon" DisplayRS(rs, scale = self.scale.get_val(), d = cpr.d) iteration = 0 dFy = DisplayCurve(parent=self, xlegend="\u03B5(%)", ylegend="Fy", yscale = 10000, ymax = 0.05) cpr.d += cpr.delt_d strain = cpr.d / rs.h0 * 100 comp_rate = rs.comp_count / rs.nsprings * 100 comp_rate_next_display = 0 first_compacted_displayed = False # Commencer la compression while comp_rate < cpr.max_comp: if self.stopped: print("Stopped.") return iteration += 1 cpr.solve() test_comp_count = rs.comp_count comp_rate = rs.comp_count / rs.nsprings * 100 # Affichage dFy.add_point(strain, cpr.Fy) if not first_compacted_displayed and comp_rate > 0.: threading.Thread(target=draw_sample).start() first_compacted_displayed = True time.sleep(2) if comp_rate >= comp_rate_next_display: threading.Thread(target=draw_sample).start() comp_rate_next_display += delta_comp_rate time.sleep(2) print("\nIteration %5d: " % iteration) print("\tCompaction rate:", comp_rate) # Incrementer le deplacement si aucun ressort n'a ete compacte if cpr.rs.comp_count == test_comp_count: cpr.d += cpr.delt_d strain = cpr.d / rs.h0 * 100 print("\tStrain: %f" % strain) threading.Thread(target=draw_sample).start() time.sleep(2) print("Done.")
def get_dir_name(self, uuid): filename = self.content[uuid][self.get_name_header()] filename = Compression.get_filename(filename) metadata = self.content[uuid][self.get_metadata_header()] dir_name = "{0}_{1}".format(metadata, filename) return dir_name
## ## Copyright 2020 Centreon ## ## 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. ## ## For more information : [email protected] ## from compression import Compression import sys if len(sys.argv) < 2: print("Usage: view-retention.py retention_file") if __name__ == '__main__': compress = Compression(sys.argv[1]) compress.unserialize()
##rs = StratifiedRockSample(nlines = 55, ncols = 23, leq0 = 1, Rl = 0.94, A0 = 1, ## Ka = 1, E0 = 1, Ke = 1, F0cr = 0.032, D = 0.03, ## F1cr = 0.028, dip = 20, t0 = 4, t1 = 8) rs = RockSample(nlines=71, ncols=31, leq0=1, Rl=0.94, A0=1, Ka=1, E0=1, Ke=1, F0cr=0.03, D=0.1) cpr = Compression(rs, F0x=0, Kbc=20, d0=0., delta_d=0.005, max_comp=50) delta_comp_rate = 2 def draw_sample(): "fonction d'affichage de l'echantillon" DisplayRS(rs, scale=8, d=cpr.d) iteration = 0 dFy = DisplayCurve(xlegend="\u03B5(%)", ylegend="Fy", yscale=10000, ymax=0.05) cpr.d += cpr.delt_d strain = cpr.d / rs.h0 * 100 comp_rate = rs.comp_count / rs.nsprings * 100
def setUp(self): self.comp = Compression(True)
def setUp(self): self.comp = Compression(False)
import threading import time from display_curve import DisplayCurve from display_rock_sample import DisplayRS from echantillon import RockSample, StratifiedRockSample from compression import Compression ##rs = StratifiedRockSample(nlines = 55, ncols = 23, leq0 = 1, Rl = 0.94, A0 = 1, ## Ka = 1, E0 = 1, Ke = 1, F0cr = 0.032, D = 0.03, ## F1cr = 0.028, dip = 20, t0 = 4, t1 = 8) rs = RockSample(nlines = 71, ncols = 31, leq0 = 1, Rl = 0.94, A0 = 1, Ka = 1, E0 = 1, Ke = 1, F0cr = 0.03, D = 0.1) cpr = Compression(rs, F0x = 0, Kbc = 20, d0 = 0., delta_d = 0.005, max_comp = 50) delta_comp_rate = 2 def draw_sample(): "fonction d'affichage de l'echantillon" DisplayRS(rs, scale = 8, d = cpr.d) iteration = 0 dFy = DisplayCurve(xlegend="\u03B5(%)", ylegend="Fy", yscale = 10000, ymax = 0.05) cpr.d += cpr.delt_d strain = cpr.d / rs.h0 * 100 comp_rate = rs.comp_count / rs.nsprings * 100 comp_rate_next_display = 0
def run(self): '''Fonction executee quand l'utilisateur clique sur "Run".''' self.stopped = False # Creation de l'echantillon en testant la validite des parametres # fournis par l'utilisateur try: rs = RockSample(self.L.get_val(), self.C.get_val(), self.leq0.get_val(), self.Rl.get_val(), self.A0.get_val(), self.Ka.get_val(), self.E0.get_val(), self.Ke.get_val(), self.F0cr.get_val(), self.D.get_val()) #rs.debug = True print(rs) cpr = Compression(rs, self.F0x.get_val(), self.Kbc.get_val(), self.d0.get_val(), self.delt_d.get_val(), self.max_comp.get_val()) delta_comp_rate = self.delta_comp.get_val() except: # si une erreur dans les parametres est detectee, soulever # l'erreur pour interrompre le programme raise def draw_sample(): "fonction d'affichage de l'echantillon" DisplayRS(rs, scale=self.scale.get_val(), d=cpr.d) iteration = 0 dFy = DisplayCurve(parent=self, xlegend="\u03B5(%)", ylegend="Fy", yscale=10000, ymax=0.05) cpr.d += cpr.delt_d strain = cpr.d / rs.h0 * 100 comp_rate = rs.comp_count / rs.nsprings * 100 comp_rate_next_display = 0 first_compacted_displayed = False # Commencer la compression while comp_rate < cpr.max_comp: if self.stopped: print("Stopped.") return iteration += 1 cpr.solve() test_comp_count = rs.comp_count comp_rate = rs.comp_count / rs.nsprings * 100 # Affichage dFy.add_point(strain, cpr.Fy) if not first_compacted_displayed and comp_rate > 0.: threading.Thread(target=draw_sample).start() first_compacted_displayed = True time.sleep(2) if comp_rate >= comp_rate_next_display: threading.Thread(target=draw_sample).start() comp_rate_next_display += delta_comp_rate time.sleep(2) print("\nIteration %5d: " % iteration) print("\tCompaction rate:", comp_rate) # Incrementer le deplacement si aucun ressort n'a ete compacte if cpr.rs.comp_count == test_comp_count: cpr.d += cpr.delt_d strain = cpr.d / rs.h0 * 100 print("\tStrain: %f" % strain) threading.Thread(target=draw_sample).start() time.sleep(2) print("Done.")
def test_it_compresses_1(): compression = Compression() input_list = ["a","a","b","b","c","c","c"] assert compression.compress(input_list) == 6
def test_it_initializes(): compression = Compression() assert isinstance(compression, Compression)
def go(deep): return Compression(deep).count(INPUT.read().replace('\n', ''))