prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>rule_008.py<|end_file_name|><|fim▁begin|> from vsg.rules import token_prefix from vsg import token lTokens = [] lTokens.append(token.signal_declaration.identifier) class rule_008(token_prefix): <|fim_middle|> <|fim▁end|>
''' This rule checks for valid prefixes on signal identifiers. Default signal prefix is *s\_*. |configuring_prefix_and_suffix_rules_link| **Violation** .. code-block:: vhdl signal wr_en : std_logic; signal rd_en : std_logic; **Fix** .. code-block:: vhdl signal s_wr_en : std_logic; signal s_rd_en : std_logic; ''' def __init__(self): token_prefix.__init__(self, 'signal', '008', lTokens) self.prefixes = ['s_'] self.solution = 'Signal identifiers'
<|file_name|>rule_008.py<|end_file_name|><|fim▁begin|> from vsg.rules import token_prefix from vsg import token lTokens = [] lTokens.append(token.signal_declaration.identifier) class rule_008(token_prefix): ''' This rule checks for valid prefixes on signal identifiers. Default signal prefix is *s\_*. |configuring_prefix_and_suffix_rules_link| **Violation** .. code-block:: vhdl signal wr_en : std_logic; signal rd_en : std_logic; **Fix** .. code-block:: vhdl signal s_wr_en : std_logic; signal s_rd_en : std_logic; ''' def __init__(self): <|fim_middle|> <|fim▁end|>
token_prefix.__init__(self, 'signal', '008', lTokens) self.prefixes = ['s_'] self.solution = 'Signal identifiers'
<|file_name|>rule_008.py<|end_file_name|><|fim▁begin|> from vsg.rules import token_prefix from vsg import token lTokens = [] lTokens.append(token.signal_declaration.identifier) class rule_008(token_prefix): ''' This rule checks for valid prefixes on signal identifiers. Default signal prefix is *s\_*. |configuring_prefix_and_suffix_rules_link| **Violation** .. code-block:: vhdl signal wr_en : std_logic; signal rd_en : std_logic; **Fix** .. code-block:: vhdl signal s_wr_en : std_logic; signal s_rd_en : std_logic; ''' def <|fim_middle|>(self): token_prefix.__init__(self, 'signal', '008', lTokens) self.prefixes = ['s_'] self.solution = 'Signal identifiers' <|fim▁end|>
__init__
<|file_name|>euler_17.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -Wall # -*- coding: utf-8 -*- """ <div id="content"> <div style="text-align:center;" class="print"><img src="images/print_page_logo.png" alt="projecteuler.net" style="border:none;" /></div> <h2>Number letter counts</h2><div id="problem_info" class="info"><h3>Problem 17</h3><span>Published on Friday, 17th May 2002, 06:00 pm; Solved by 88413; Difficulty rating: 5%</span></div> <div class="problem_content" role="problem"> <p>If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.</p> <p>If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? </p> <br /> <p class="note"><b>NOTE:</b> Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.</p> </div><br /> <br /></div> """ s={0:"",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"forty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety"} for i in range(1,1000): if(not i in s.keys()): if(i<100):<|fim▁hole|> s[i]=s[i/10*10]+s[i%10] else: s[i]=s[i/100]+"hundred" if(i%100): s[i]+="and"+s[i%100] s[1000]="onethousand" total=0; for i in s.values(): total+=len(i) print total<|fim▁end|>
<|file_name|>euler_17.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -Wall # -*- coding: utf-8 -*- """ <div id="content"> <div style="text-align:center;" class="print"><img src="images/print_page_logo.png" alt="projecteuler.net" style="border:none;" /></div> <h2>Number letter counts</h2><div id="problem_info" class="info"><h3>Problem 17</h3><span>Published on Friday, 17th May 2002, 06:00 pm; Solved by 88413; Difficulty rating: 5%</span></div> <div class="problem_content" role="problem"> <p>If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.</p> <p>If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? </p> <br /> <p class="note"><b>NOTE:</b> Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.</p> </div><br /> <br /></div> """ s={0:"",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"forty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety"} for i in range(1,1000): if(not i in s.keys()): <|fim_middle|> s[1000]="onethousand" total=0; for i in s.values(): total+=len(i) print total <|fim▁end|>
if(i<100): s[i]=s[i/10*10]+s[i%10] else: s[i]=s[i/100]+"hundred" if(i%100): s[i]+="and"+s[i%100]
<|file_name|>euler_17.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -Wall # -*- coding: utf-8 -*- """ <div id="content"> <div style="text-align:center;" class="print"><img src="images/print_page_logo.png" alt="projecteuler.net" style="border:none;" /></div> <h2>Number letter counts</h2><div id="problem_info" class="info"><h3>Problem 17</h3><span>Published on Friday, 17th May 2002, 06:00 pm; Solved by 88413; Difficulty rating: 5%</span></div> <div class="problem_content" role="problem"> <p>If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.</p> <p>If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? </p> <br /> <p class="note"><b>NOTE:</b> Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.</p> </div><br /> <br /></div> """ s={0:"",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"forty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety"} for i in range(1,1000): if(not i in s.keys()): if(i<100): <|fim_middle|> else: s[i]=s[i/100]+"hundred" if(i%100): s[i]+="and"+s[i%100] s[1000]="onethousand" total=0; for i in s.values(): total+=len(i) print total <|fim▁end|>
s[i]=s[i/10*10]+s[i%10]
<|file_name|>euler_17.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -Wall # -*- coding: utf-8 -*- """ <div id="content"> <div style="text-align:center;" class="print"><img src="images/print_page_logo.png" alt="projecteuler.net" style="border:none;" /></div> <h2>Number letter counts</h2><div id="problem_info" class="info"><h3>Problem 17</h3><span>Published on Friday, 17th May 2002, 06:00 pm; Solved by 88413; Difficulty rating: 5%</span></div> <div class="problem_content" role="problem"> <p>If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.</p> <p>If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? </p> <br /> <p class="note"><b>NOTE:</b> Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.</p> </div><br /> <br /></div> """ s={0:"",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"forty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety"} for i in range(1,1000): if(not i in s.keys()): if(i<100): s[i]=s[i/10*10]+s[i%10] else: <|fim_middle|> s[1000]="onethousand" total=0; for i in s.values(): total+=len(i) print total <|fim▁end|>
s[i]=s[i/100]+"hundred" if(i%100): s[i]+="and"+s[i%100]
<|file_name|>euler_17.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -Wall # -*- coding: utf-8 -*- """ <div id="content"> <div style="text-align:center;" class="print"><img src="images/print_page_logo.png" alt="projecteuler.net" style="border:none;" /></div> <h2>Number letter counts</h2><div id="problem_info" class="info"><h3>Problem 17</h3><span>Published on Friday, 17th May 2002, 06:00 pm; Solved by 88413; Difficulty rating: 5%</span></div> <div class="problem_content" role="problem"> <p>If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.</p> <p>If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? </p> <br /> <p class="note"><b>NOTE:</b> Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.</p> </div><br /> <br /></div> """ s={0:"",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"forty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety"} for i in range(1,1000): if(not i in s.keys()): if(i<100): s[i]=s[i/10*10]+s[i%10] else: s[i]=s[i/100]+"hundred" if(i%100): <|fim_middle|> s[1000]="onethousand" total=0; for i in s.values(): total+=len(i) print total <|fim▁end|>
s[i]+="and"+s[i%100]
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6),<|fim▁hole|> (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main()<|fim▁end|>
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): <|fim_middle|> if __name__ == "__main__": unittest.main() <|fim▁end|>
def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual)
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected <|fim_middle|> def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main() <|fim▁end|>
self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) )
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): <|fim_middle|> def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main() <|fim▁end|>
actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual)
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): <|fim_middle|> def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main() <|fim▁end|>
for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message)
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): <|fim_middle|> if __name__ == "__main__": unittest.main() <|fim▁end|>
actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual)
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": <|fim_middle|> <|fim▁end|>
unittest.main()
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def <|fim_middle|>(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main() <|fim▁end|>
setUp
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def <|fim_middle|>(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main() <|fim▁end|>
test_greatest_common_divisor_zero
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def <|fim_middle|>(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def test_next_smaller_divisor(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main() <|fim▁end|>
test_greatest_common_divisor
<|file_name|>test_greatest_common_divisor.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python3 import unittest import greatest_common_divisor as gcd class TestGreatestCommonDivisor(unittest.TestCase): def setUp(self): # use tuple of tuples instead of list of tuples because data won't change # https://en.wikipedia.org/wiki/Algorithm # a, b, expected self.test_data = ((12, 8, 4), (9, 12, 3), (54, 24, 6), (3009, 884, 17), (40902, 24140, 34), (14157, 5950, 1) ) def test_greatest_common_divisor_zero(self): actual = gcd.GreatestCommonDivisor.greatest_common_divisor(12, 0) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(0, 13) self.assertEqual(0, actual) actual = gcd.GreatestCommonDivisor.greatest_common_divisor(-5, 13) self.assertEqual(0, actual) def test_greatest_common_divisor(self): for test_case in self.test_data: expected = test_case[2] actual = gcd.GreatestCommonDivisor.greatest_common_divisor(test_case[0], test_case[1]) fail_message = str.format("expected {0} but got {1}", expected, actual) self.assertEqual(expected, actual, fail_message) def <|fim_middle|>(self): actual = gcd.GreatestCommonDivisor.next_smaller_divisor(8, 8) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 12) self.assertEqual(6, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 6) self.assertEqual(4, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 4) self.assertEqual(3, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 3) self.assertEqual(2, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 2) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(12, 1) self.assertEqual(1, actual) actual = gcd.GreatestCommonDivisor.next_smaller_divisor(54, 18) self.assertEqual(9, actual) if __name__ == "__main__": unittest.main() <|fim▁end|>
test_next_smaller_divisor
<|file_name|>urls.py<|end_file_name|><|fim▁begin|>from django.conf.urls import url from admin.nodes import views app_name = 'admin' urlpatterns = [ url(r'^$', views.NodeFormView.as_view(), name='search'), url(r'^flagged_spam$', views.NodeFlaggedSpamList.as_view(), name='flagged-spam'), url(r'^known_spam$', views.NodeKnownSpamList.as_view(), name='known-spam'), url(r'^known_ham$', views.NodeKnownHamList.as_view(), name='known-ham'), url(r'^(?P<guid>[a-z0-9]+)/$', views.NodeView.as_view(),<|fim▁hole|> url(r'^registration_list/$', views.RegistrationListView.as_view(), name='registrations'), url(r'^stuck_registration_list/$', views.StuckRegistrationListView.as_view(), name='stuck-registrations'), url(r'^(?P<guid>[a-z0-9]+)/update_embargo/$', views.RegistrationUpdateEmbargoView.as_view(), name='update_embargo'), url(r'^(?P<guid>[a-z0-9]+)/remove/$', views.NodeDeleteView.as_view(), name='remove'), url(r'^(?P<guid>[a-z0-9]+)/restore/$', views.NodeDeleteView.as_view(), name='restore'), url(r'^(?P<guid>[a-z0-9]+)/confirm_spam/$', views.NodeConfirmSpamView.as_view(), name='confirm-spam'), url(r'^(?P<guid>[a-z0-9]+)/confirm_ham/$', views.NodeConfirmHamView.as_view(), name='confirm-ham'), url(r'^(?P<guid>[a-z0-9]+)/reindex_share_node/$', views.NodeReindexShare.as_view(), name='reindex-share-node'), url(r'^(?P<guid>[a-z0-9]+)/reindex_elastic_node/$', views.NodeReindexElastic.as_view(), name='reindex-elastic-node'), url(r'^(?P<guid>[a-z0-9]+)/restart_stuck_registrations/$', views.RestartStuckRegistrationsView.as_view(), name='restart-stuck-registrations'), url(r'^(?P<guid>[a-z0-9]+)/remove_stuck_registrations/$', views.RemoveStuckRegistrationsView.as_view(), name='remove-stuck-registrations'), url(r'^(?P<guid>[a-z0-9]+)/remove_user/(?P<user_id>[a-z0-9]+)/$', views.NodeRemoveContributorView.as_view(), name='remove_user'), ]<|fim▁end|>
name='node'), url(r'^(?P<guid>[a-z0-9]+)/logs/$', views.AdminNodeLogView.as_view(), name='node-logs'),
<|file_name|>shtest-format.py<|end_file_name|><|fim▁begin|># Check the various features of the ShTest format. # # RUN: not %{lit} -j 1 -v %{inputs}/shtest-format > %t.out # RUN: FileCheck < %t.out %s # # END. # CHECK: -- Testing: # CHECK: FAIL: shtest-format :: external_shell/fail.txt # CHECK: *** TEST 'shtest-format :: external_shell/fail.txt' FAILED *** # CHECK: Command Output (stderr): # CHECK: cat: does-not-exist: No such file or directory # CHECK: -- # CHECK: PASS: shtest-format :: external_shell/pass.txt # CHECK: FAIL: shtest-format :: fail.txt # CHECK: UNRESOLVED: shtest-format :: no-test-line.txt # CHECK: PASS: shtest-format :: pass.txt # CHECK: UNSUPPORTED: shtest-format :: requires-missing.txt # CHECK: PASS: shtest-format :: requires-present.txt # CHECK: UNSUPPORTED: shtest-format :: unsupported_dir/some-test.txt # CHECK: XFAIL: shtest-format :: xfail-feature.txt # CHECK: XFAIL: shtest-format :: xfail-target.txt # CHECK: XFAIL: shtest-format :: xfail.txt # CHECK: XPASS: shtest-format :: xpass.txt # CHECK: Testing Time # CHECK: Unexpected Passing Tests (1) # CHECK: shtest-format :: xpass.txt # CHECK: Failing Tests (2) # CHECK: shtest-format :: external_shell/fail.txt # CHECK: shtest-format :: fail.txt # CHECK: Expected Passes : 3 # CHECK: Expected Failures : 3 # CHECK: Unsupported Tests : 2 # CHECK: Unresolved Tests : 1<|fim▁hole|><|fim▁end|>
# CHECK: Unexpected Passes : 1 # CHECK: Unexpected Failures: 2
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub<|fim▁hole|> self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main()<|fim▁end|>
self.pub_client = pubsub.PublisherClient()
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): <|fim_middle|> if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False)
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): <|fim_middle|> def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60)
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): <|fim_middle|> def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
"""Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8'))
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): <|fim_middle|> @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic])
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. <|fim_middle|> if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False)
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': <|fim_middle|> <|fim▁end|>
logging.getLogger().setLevel(logging.DEBUG) unittest.main()
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def <|fim_middle|>(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
setUp
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def <|fim_middle|>(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
_inject_numbers
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def <|fim_middle|>(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def test_streaming_wordcount_it(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
tearDown
<|file_name|>streaming_wordcount_it_test.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. # """End-to-end test for the streaming wordcount example.""" from __future__ import absolute_import import logging import unittest import uuid from builtins import range from hamcrest.core.core.allof import all_of from nose.plugins.attrib import attr from apache_beam.examples import streaming_wordcount from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher from apache_beam.runners.runner import PipelineState from apache_beam.testing import test_utils from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher from apache_beam.testing.test_pipeline import TestPipeline INPUT_TOPIC = 'wc_topic_input' OUTPUT_TOPIC = 'wc_topic_output' INPUT_SUB = 'wc_subscription_input' OUTPUT_SUB = 'wc_subscription_output' DEFAULT_INPUT_NUMBERS = 500 WAIT_UNTIL_FINISH_DURATION = 6 * 60 * 1000 # in milliseconds class StreamingWordCountIT(unittest.TestCase): def setUp(self): self.test_pipeline = TestPipeline(is_integration_test=True) self.project = self.test_pipeline.get_option('project') self.uuid = str(uuid.uuid4()) # Set up PubSub environment. from google.cloud import pubsub self.pub_client = pubsub.PublisherClient() self.input_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, INPUT_TOPIC + self.uuid)) self.output_topic = self.pub_client.create_topic( self.pub_client.topic_path(self.project, OUTPUT_TOPIC + self.uuid)) self.sub_client = pubsub.SubscriberClient() self.input_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, INPUT_SUB + self.uuid), self.input_topic.name) self.output_sub = self.sub_client.create_subscription( self.sub_client.subscription_path(self.project, OUTPUT_SUB + self.uuid), self.output_topic.name, ack_deadline_seconds=60) def _inject_numbers(self, topic, num_messages): """Inject numbers as test data to PubSub.""" logging.debug('Injecting %d numbers to topic %s', num_messages, topic.name) for n in range(num_messages): self.pub_client.publish(self.input_topic.name, str(n).encode('utf-8')) def tearDown(self): test_utils.cleanup_subscriptions(self.sub_client, [self.input_sub, self.output_sub]) test_utils.cleanup_topics(self.pub_client, [self.input_topic, self.output_topic]) @attr('IT') def <|fim_middle|>(self): # Build expected dataset. expected_msg = [('%d: 1' % num).encode('utf-8') for num in range(DEFAULT_INPUT_NUMBERS)] # Set extra options to the pipeline for test purpose state_verifier = PipelineStateMatcher(PipelineState.RUNNING) pubsub_msg_verifier = PubSubMessageMatcher(self.project, self.output_sub.name, expected_msg, timeout=400) extra_opts = {'input_subscription': self.input_sub.name, 'output_topic': self.output_topic.name, 'wait_until_finish_duration': WAIT_UNTIL_FINISH_DURATION, 'on_success_matcher': all_of(state_verifier, pubsub_msg_verifier)} # Generate input data and inject to PubSub. self._inject_numbers(self.input_topic, DEFAULT_INPUT_NUMBERS) # Get pipeline options from command argument: --test-pipeline-options, # and start pipeline job by calling pipeline main function. streaming_wordcount.run( self.test_pipeline.get_full_options_as_args(**extra_opts), save_main_session=False) if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main() <|fim▁end|>
test_streaming_wordcount_it
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook<|fim▁hole|> class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT)<|fim▁end|>
with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template)
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): <|fim_middle|> class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template)
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): <|fim_middle|> def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
self._js_model = js_model
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): <|fim_middle|> class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template)
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): <|fim_middle|> class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config)
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): <|fim_middle|> def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
self._output = output self._model = model self._config = config
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): <|fim_middle|> class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
JsResultWriter(self._output).write(self._model, self._config)
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): <|fim_middle|> class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path))
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): <|fim_middle|> def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0])
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): <|fim_middle|> def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index))
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): <|fim_middle|> class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path))
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): <|fim_middle|> <|fim▁end|>
def write(self, path, config): self._write_file(path, config, REPORT)
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): <|fim_middle|> <|fim▁end|>
self._write_file(path, config, REPORT)
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: <|fim_middle|> def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
self._write_split_logs(splitext(path)[0])
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def <|fim_middle|>(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
__init__
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def <|fim_middle|>(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
_write_file
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def <|fim_middle|>(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
__init__
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def <|fim_middle|>(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
write
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def <|fim_middle|>(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
write
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def <|fim_middle|>(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
_write_split_logs
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def <|fim_middle|>(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
_write_split_log
<|file_name|>logreportwriters.py<|end_file_name|><|fim▁begin|># Copyright 2008-2012 Nokia Siemens Networks Oyj # # 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 with_statement from os.path import basename, splitext import codecs from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT from robot.utils import utf8open from .jswriter import JsResultWriter, SplitLogWriter class _LogReportWriter(object): def __init__(self, js_model): self._js_model = js_model def _write_file(self, path, config, template): outfile = codecs.open(path, 'wb', encoding='UTF-8')\ if isinstance(path, basestring) else path # unit test hook with outfile: model_writer = RobotModelWriter(outfile, self._js_model, config) writer = HtmlFileWriter(outfile, model_writer) writer.write(template) class RobotModelWriter(ModelWriter): def __init__(self, output, model, config): self._output = output self._model = model self._config = config def write(self, line): JsResultWriter(self._output).write(self._model, self._config) class LogWriter(_LogReportWriter): def write(self, path, config): self._write_file(path, config, LOG) if self._js_model.split_results: self._write_split_logs(splitext(path)[0]) def _write_split_logs(self, base): for index, (keywords, strings) in enumerate(self._js_model.split_results): index += 1 # enumerate accepts start index only in Py 2.6+ self._write_split_log(index, keywords, strings, '%s-%d.js' % (base, index)) def _write_split_log(self, index, keywords, strings, path): with utf8open(path, 'wb') as outfile: writer = SplitLogWriter(outfile) writer.write(keywords, strings, index, basename(path)) class ReportWriter(_LogReportWriter): def <|fim_middle|>(self, path, config): self._write_file(path, config, REPORT) <|fim▁end|>
write
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse<|fim▁hole|> import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile')<|fim▁end|>
import pprint import proteindf_bridge as bridge
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest <|fim_middle|> def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): <|fim_middle|> def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain)
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): <|fim_middle|> if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path)
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: <|fim_middle|> # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path))
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: <|fim_middle|> if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path)
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: <|fim_middle|> bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
print("output brd file: {}".format(output_path))
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() <|fim_middle|> <|fim▁end|>
main() # pr.disable() # pr.dump_stats('program.profile')
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def <|fim_middle|>(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
get_rest_of_frame_molecule
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def <|fim_middle|>(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def main(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
assign_rest_molecule
<|file_name|>brd-restructure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python # -*- coding: utf-8 -*- import os import argparse import pprint import proteindf_bridge as bridge import logging import logging.config def get_rest_of_frame_molecule(frame_molecule, selected_molecule): # calc the rest selector = bridge.Select_AtomGroup(selected_molecule) selected = frame_molecule.select(selector) rest_molecule = frame_molecule ^ selected return rest_molecule def assign_rest_molecule(rest_molecule, output_atom_group, model_id="model_1", chain_id="Z", res_name="UNK"): chain = bridge.AtomGroup() res = bridge.AtomGroup() res.name = res_name atom_id = 1 for atom in rest_molecule.get_atom_list(): res.set_atom(atom_id, atom) atom_id += 1 chain.set_group(1, res) output_atom_group[model_id].set_group(chain_id, chain) def <|fim_middle|>(): parser = argparse.ArgumentParser( description='restructure brd file by reference file') parser.add_argument('target_brd_path', nargs=1, help='target brd file') parser.add_argument('ref_brd_path', nargs=1, help='reference brd file') parser.add_argument('-o', '--output_path', nargs=1, default=["output.brd"]) parser.add_argument('-r', '--range', nargs=1, default=[1.0E-5]) parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() # print(args) target_brd_path = args.target_brd_path[0] ref_brd_path = args.ref_brd_path[0] output_path = args.output_path[0] range = float(args.range[0]) verbose = args.verbose if verbose: print("target: {}".format(target_brd_path)) print("reference: {}".format(ref_brd_path)) # load target_ag = bridge.load_atomgroup(target_brd_path) ref_ag = bridge.load_atomgroup(ref_brd_path) # matching #target_selector = bridge.Select_AtomGroup(target_ag) #restructured = ref_ag.select(target_selector) # calc the rest #rest_of_target = get_rest_of_frame_molecule(target_ag, restructured) #assign_rest_molecule(rest_of_target, restructured) restructured = target_ag.restructure(ref_ag, range) if output_path: if verbose: print("output brd file: {}".format(output_path)) bridge.save_atomgroup(restructured, output_path) if __name__ == '__main__': #import cProfile #pr = cProfile.Profile() # pr.enable() main() # pr.disable() # pr.dump_stats('program.profile') <|fim▁end|>
main
<|file_name|>setup.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # # # TheVirtualBrain-Framework Package. This package holds all Data Management, and # Web-UI helpful to run brain-simulations. To use it, you also need do download # TheVirtualBrain-Scientific Package (for simulators). See content of the # documentation-folder for more details. See also http://www.thevirtualbrain.org # # (c) 2012-2013, Baycrest Centre for Geriatric Care ("Baycrest") # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License version 2 as published by the Free # Software Foundation. This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of <|fim▁hole|># http://www.gnu.org/licenses/old-licenses/gpl-2.0 # # # CITATION: # When using The Virtual Brain for scientific publications, please cite it as follows: # # Paula Sanz Leon, Stuart A. Knock, M. Marmaduke Woodman, Lia Domide, # Jochen Mersmann, Anthony R. McIntosh, Viktor Jirsa (2013) # The Virtual Brain: a simulator of primate brain network dynamics. # Frontiers in Neuroinformatics (7:10. doi: 10.3389/fninf.2013.00010) # # """ Install TVB Framework package for developers. Execute: python setup.py install/develop """ import os import shutil import setuptools VERSION = "1.4" TVB_TEAM = "Mihai Andrei, Lia Domide, Ionel Ortelecan, Bogdan Neacsa, Calin Pavel, " TVB_TEAM += "Stuart Knock, Marmaduke Woodman, Paula Sansz Leon, " TVB_INSTALL_REQUIREMENTS = ["apscheduler", "beautifulsoup", "cherrypy", "genshi", "cfflib", "formencode==1.3.0a1", "h5py==2.3.0", "lxml", "minixsv", "mod_pywebsocket", "networkx", "nibabel", "numpy", "numexpr", "psutil", "scikit-learn", "scipy", "simplejson", "PIL>=1.1.7", "sqlalchemy==0.7.8", "sqlalchemy-migrate==0.7.2", "matplotlib==1.2.1"] EXCLUDE_INTROSPECT_FOLDERS = [folder for folder in os.listdir(".") if os.path.isdir(os.path.join(".", folder)) and folder != "tvb"] setuptools.setup(name="tvb", version=VERSION, packages=setuptools.find_packages(exclude=EXCLUDE_INTROSPECT_FOLDERS), license="GPL v2", author=TVB_TEAM, author_email='[email protected]', include_package_data=True, install_requires=TVB_INSTALL_REQUIREMENTS, extras_require={'postgres': ["psycopg2"]}) ## Clean after install shutil.rmtree('tvb.egg-info', True)<|fim▁end|>
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. You should have received a copy of the GNU General # Public License along with this program; if not, you can download it here
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) <|fim▁hole|> drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: build_image(i, SUCCESS).save(file)<|fim▁end|>
drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW)
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): <|fim_middle|> BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: build_image(i, SUCCESS).save(file) <|fim▁end|>
if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), )
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): <|fim_middle|> os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: build_image(i, SUCCESS).save(file) <|fim▁end|>
image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): if hex[0] == '#': <|fim_middle|> return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: build_image(i, SUCCESS).save(file) <|fim▁end|>
hex = hex[1:]
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: <|fim_middle|> elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: build_image(i, SUCCESS).save(file) <|fim▁end|>
build_image(i, ERROR).save(file)
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: <|fim_middle|> else: build_image(i, SUCCESS).save(file) <|fim▁end|>
build_image(i, WARNING).save(file)
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: <|fim_middle|> <|fim▁end|>
build_image(i, SUCCESS).save(file)
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def <|fim_middle|>(hex): if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def build_image(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: build_image(i, SUCCESS).save(file) <|fim▁end|>
hex_colour
<|file_name|>badge_maker.py<|end_file_name|><|fim▁begin|>""" Drone.io badge generator. Currently set up to work on Mac. Requires Pillow. """ import os from PIL import Image, ImageDraw, ImageFont SIZE = (95, 18) def hex_colour(hex): if hex[0] == '#': hex = hex[1:] return ( int(hex[:2], 16), int(hex[2:4], 16), int(hex[4:6], 16), ) BACKGROUND = hex_colour('#4A4A4A') SUCCESS = hex_colour('#94B944') WARNING = hex_colour('#E4A83C') ERROR = hex_colour('#B10610') SUCCESS_CUTOFF = 85 WARNING_CUTOFF = 45 FONT = ImageFont.truetype(size=10, filename="/Library/Fonts/Arial.ttf") FONT_SHADOW = hex_colour('#525252') PADDING_TOP = 3 def <|fim_middle|>(percentage, colour): image = Image.new('RGB', SIZE, color=BACKGROUND) drawing = ImageDraw.Draw(image) drawing.rectangle([(55, 0), SIZE], colour, colour) drawing.text((8, PADDING_TOP+1), 'coverage', font=FONT, fill=FONT_SHADOW) drawing.text((7, PADDING_TOP), 'coverage', font=FONT) drawing.text((63, PADDING_TOP+1), '%s%%' % percentage, font=FONT, fill=FONT_SHADOW) drawing.text((62, PADDING_TOP), '%s%%' % percentage, font=FONT) return image os.chdir('_build') for i in range(101): filename = '%i.png' % i file = open(filename, 'wb') if i < WARNING_CUTOFF: build_image(i, ERROR).save(file) elif i < SUCCESS_CUTOFF: build_image(i, WARNING).save(file) else: build_image(i, SUCCESS).save(file) <|fim▁end|>
build_image
<|file_name|>_showexponent.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators<|fim▁hole|> class ShowexponentValidator(_plotly_utils.basevalidators.EnumeratedValidator): def __init__( self, plotly_name="showexponent", parent_name="scatterpolar.marker.colorbar", **kwargs ): super(ShowexponentValidator, self).__init__( plotly_name=plotly_name, parent_name=parent_name, edit_type=kwargs.pop("edit_type", "colorbars"), values=kwargs.pop("values", ["all", "first", "last", "none"]), **kwargs )<|fim▁end|>
<|file_name|>_showexponent.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators class ShowexponentValidator(_plotly_utils.basevalidators.EnumeratedValidator): <|fim_middle|> <|fim▁end|>
def __init__( self, plotly_name="showexponent", parent_name="scatterpolar.marker.colorbar", **kwargs ): super(ShowexponentValidator, self).__init__( plotly_name=plotly_name, parent_name=parent_name, edit_type=kwargs.pop("edit_type", "colorbars"), values=kwargs.pop("values", ["all", "first", "last", "none"]), **kwargs )
<|file_name|>_showexponent.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators class ShowexponentValidator(_plotly_utils.basevalidators.EnumeratedValidator): def __init__( self, plotly_name="showexponent", parent_name="scatterpolar.marker.colorbar", **kwargs ): <|fim_middle|> <|fim▁end|>
super(ShowexponentValidator, self).__init__( plotly_name=plotly_name, parent_name=parent_name, edit_type=kwargs.pop("edit_type", "colorbars"), values=kwargs.pop("values", ["all", "first", "last", "none"]), **kwargs )
<|file_name|>_showexponent.py<|end_file_name|><|fim▁begin|>import _plotly_utils.basevalidators class ShowexponentValidator(_plotly_utils.basevalidators.EnumeratedValidator): def <|fim_middle|>( self, plotly_name="showexponent", parent_name="scatterpolar.marker.colorbar", **kwargs ): super(ShowexponentValidator, self).__init__( plotly_name=plotly_name, parent_name=parent_name, edit_type=kwargs.pop("edit_type", "colorbars"), values=kwargs.pop("values", ["all", "first", "last", "none"]), **kwargs ) <|fim▁end|>
__init__
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # © 2014 Elico Corp (https://www.elico-corp.com) # Licence AGPL-3.0 or later(http://www.gnu.org/licenses/agpl.html) <|fim▁hole|><|fim▁end|>
import invoice
<|file_name|>Plugins.py<|end_file_name|><|fim▁begin|># # # (C) Copyright 2001 The Internet (Aust) Pty Ltd # ACN: 082 081 472 ABN: 83 082 081 472 # All Rights Reserved # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. #<|fim▁hole|>import string import time from Globals import ImageFile, HTMLFile, HTML, MessageDialog, package_home from OFS.Folder import Folder class PluginRegister: def __init__(self, name, description, pluginClass, pluginStartForm, pluginStartMethod, pluginEditForm=None, pluginEditMethod=None): self.name=name #No Spaces please... self.description=description self.plugin=pluginClass self.manage_addForm=pluginStartForm self.manage_addMethod=pluginStartMethod self.manage_editForm=pluginEditForm self.manage_editMethod=pluginEditMethod class CryptoPluginRegister: def __init__(self, name, crypto, description, pluginMethod): self.name = name #No Spaces please... self.cryptoMethod = crypto self.description = description self.plugin = pluginMethod<|fim▁end|>
# Author: Andrew Milton <[email protected]> # $Id: Plugins.py,v 1.5 2004/11/10 14:15:33 akm Exp $ import App, Globals, OFS
<|file_name|>Plugins.py<|end_file_name|><|fim▁begin|># # # (C) Copyright 2001 The Internet (Aust) Pty Ltd # ACN: 082 081 472 ABN: 83 082 081 472 # All Rights Reserved # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Author: Andrew Milton <[email protected]> # $Id: Plugins.py,v 1.5 2004/11/10 14:15:33 akm Exp $ import App, Globals, OFS import string import time from Globals import ImageFile, HTMLFile, HTML, MessageDialog, package_home from OFS.Folder import Folder class PluginRegister: <|fim_middle|> class CryptoPluginRegister: def __init__(self, name, crypto, description, pluginMethod): self.name = name #No Spaces please... self.cryptoMethod = crypto self.description = description self.plugin = pluginMethod <|fim▁end|>
def __init__(self, name, description, pluginClass, pluginStartForm, pluginStartMethod, pluginEditForm=None, pluginEditMethod=None): self.name=name #No Spaces please... self.description=description self.plugin=pluginClass self.manage_addForm=pluginStartForm self.manage_addMethod=pluginStartMethod self.manage_editForm=pluginEditForm self.manage_editMethod=pluginEditMethod
<|file_name|>Plugins.py<|end_file_name|><|fim▁begin|># # # (C) Copyright 2001 The Internet (Aust) Pty Ltd # ACN: 082 081 472 ABN: 83 082 081 472 # All Rights Reserved # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Author: Andrew Milton <[email protected]> # $Id: Plugins.py,v 1.5 2004/11/10 14:15:33 akm Exp $ import App, Globals, OFS import string import time from Globals import ImageFile, HTMLFile, HTML, MessageDialog, package_home from OFS.Folder import Folder class PluginRegister: def __init__(self, name, description, pluginClass, pluginStartForm, pluginStartMethod, pluginEditForm=None, pluginEditMethod=None): <|fim_middle|> class CryptoPluginRegister: def __init__(self, name, crypto, description, pluginMethod): self.name = name #No Spaces please... self.cryptoMethod = crypto self.description = description self.plugin = pluginMethod <|fim▁end|>
self.name=name #No Spaces please... self.description=description self.plugin=pluginClass self.manage_addForm=pluginStartForm self.manage_addMethod=pluginStartMethod self.manage_editForm=pluginEditForm self.manage_editMethod=pluginEditMethod
<|file_name|>Plugins.py<|end_file_name|><|fim▁begin|># # # (C) Copyright 2001 The Internet (Aust) Pty Ltd # ACN: 082 081 472 ABN: 83 082 081 472 # All Rights Reserved # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Author: Andrew Milton <[email protected]> # $Id: Plugins.py,v 1.5 2004/11/10 14:15:33 akm Exp $ import App, Globals, OFS import string import time from Globals import ImageFile, HTMLFile, HTML, MessageDialog, package_home from OFS.Folder import Folder class PluginRegister: def __init__(self, name, description, pluginClass, pluginStartForm, pluginStartMethod, pluginEditForm=None, pluginEditMethod=None): self.name=name #No Spaces please... self.description=description self.plugin=pluginClass self.manage_addForm=pluginStartForm self.manage_addMethod=pluginStartMethod self.manage_editForm=pluginEditForm self.manage_editMethod=pluginEditMethod class CryptoPluginRegister: <|fim_middle|> <|fim▁end|>
def __init__(self, name, crypto, description, pluginMethod): self.name = name #No Spaces please... self.cryptoMethod = crypto self.description = description self.plugin = pluginMethod
<|file_name|>Plugins.py<|end_file_name|><|fim▁begin|># # # (C) Copyright 2001 The Internet (Aust) Pty Ltd # ACN: 082 081 472 ABN: 83 082 081 472 # All Rights Reserved # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Author: Andrew Milton <[email protected]> # $Id: Plugins.py,v 1.5 2004/11/10 14:15:33 akm Exp $ import App, Globals, OFS import string import time from Globals import ImageFile, HTMLFile, HTML, MessageDialog, package_home from OFS.Folder import Folder class PluginRegister: def __init__(self, name, description, pluginClass, pluginStartForm, pluginStartMethod, pluginEditForm=None, pluginEditMethod=None): self.name=name #No Spaces please... self.description=description self.plugin=pluginClass self.manage_addForm=pluginStartForm self.manage_addMethod=pluginStartMethod self.manage_editForm=pluginEditForm self.manage_editMethod=pluginEditMethod class CryptoPluginRegister: def __init__(self, name, crypto, description, pluginMethod): <|fim_middle|> <|fim▁end|>
self.name = name #No Spaces please... self.cryptoMethod = crypto self.description = description self.plugin = pluginMethod
<|file_name|>Plugins.py<|end_file_name|><|fim▁begin|># # # (C) Copyright 2001 The Internet (Aust) Pty Ltd # ACN: 082 081 472 ABN: 83 082 081 472 # All Rights Reserved # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Author: Andrew Milton <[email protected]> # $Id: Plugins.py,v 1.5 2004/11/10 14:15:33 akm Exp $ import App, Globals, OFS import string import time from Globals import ImageFile, HTMLFile, HTML, MessageDialog, package_home from OFS.Folder import Folder class PluginRegister: def <|fim_middle|>(self, name, description, pluginClass, pluginStartForm, pluginStartMethod, pluginEditForm=None, pluginEditMethod=None): self.name=name #No Spaces please... self.description=description self.plugin=pluginClass self.manage_addForm=pluginStartForm self.manage_addMethod=pluginStartMethod self.manage_editForm=pluginEditForm self.manage_editMethod=pluginEditMethod class CryptoPluginRegister: def __init__(self, name, crypto, description, pluginMethod): self.name = name #No Spaces please... self.cryptoMethod = crypto self.description = description self.plugin = pluginMethod <|fim▁end|>
__init__
<|file_name|>Plugins.py<|end_file_name|><|fim▁begin|># # # (C) Copyright 2001 The Internet (Aust) Pty Ltd # ACN: 082 081 472 ABN: 83 082 081 472 # All Rights Reserved # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Author: Andrew Milton <[email protected]> # $Id: Plugins.py,v 1.5 2004/11/10 14:15:33 akm Exp $ import App, Globals, OFS import string import time from Globals import ImageFile, HTMLFile, HTML, MessageDialog, package_home from OFS.Folder import Folder class PluginRegister: def __init__(self, name, description, pluginClass, pluginStartForm, pluginStartMethod, pluginEditForm=None, pluginEditMethod=None): self.name=name #No Spaces please... self.description=description self.plugin=pluginClass self.manage_addForm=pluginStartForm self.manage_addMethod=pluginStartMethod self.manage_editForm=pluginEditForm self.manage_editMethod=pluginEditMethod class CryptoPluginRegister: def <|fim_middle|>(self, name, crypto, description, pluginMethod): self.name = name #No Spaces please... self.cryptoMethod = crypto self.description = description self.plugin = pluginMethod <|fim▁end|>
__init__
<|file_name|>test_demos_desordre.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- import os from abjad import abjad_configuration from abjad.demos import desordre <|fim▁hole|> lilypond_file = desordre.make_desordre_lilypond_file()<|fim▁end|>
def test_demos_desordre_01():
<|file_name|>test_demos_desordre.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- import os from abjad import abjad_configuration from abjad.demos import desordre def test_demos_desordre_01(): <|fim_middle|> <|fim▁end|>
lilypond_file = desordre.make_desordre_lilypond_file()
<|file_name|>test_demos_desordre.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- import os from abjad import abjad_configuration from abjad.demos import desordre def <|fim_middle|>(): lilypond_file = desordre.make_desordre_lilypond_file()<|fim▁end|>
test_demos_desordre_01
<|file_name|>01-document.py<|end_file_name|><|fim▁begin|>import os, sys; sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..")) import codecs from pattern.vector import Document, PORTER, LEMMA # A Document is a "bag-of-words" that splits a string into words and counts them. # A list of words or dictionary of (word, count)-items can also be given. # Words (or more generally "features") and their word count ("feature weights") # can be used to compare documents. The word count in a document is normalized # between 0.0-1.0 so that shorted documents can be compared to longer documents. # Words can be stemmed or lemmatized before counting them. # The purpose of stemming is to bring variant forms a word together. # For example, "conspiracy" and "conspired" are both stemmed to "conspir". # Nowadays, lemmatization is usually preferred over stemming, # e.g., "conspiracies" => "conspiracy", "conspired" => "conspire". s = """ The shuttle Discovery, already delayed three times by technical problems and bad weather, was grounded again Friday, this time by a potentially dangerous gaseous hydrogen leak in a vent line attached to the ship's external tank. The Discovery was initially scheduled to make its 39th and final flight last Monday, bearing fresh supplies and an intelligent robot for the International Space Station. But complications delayed the flight from Monday to Friday, when the hydrogen leak led NASA to conclude that the shuttle would not be ready to launch before its flight window closed this Monday. """ # With threshold=1, only words that occur more than once are counted. # With stopwords=False, words like "the", "and", "I", "is" are ignored. document = Document(s, threshold=1, stopwords=False) print document.words print # The /corpus folder contains texts mined from Wikipedia. # Below is the mining script (we already executed it for you): #import os, codecs #from pattern.web import Wikipedia # #w = Wikipedia() #for q in ( # "badger", "bear", "dog", "dolphin", "lion", "parakeet", # "rabbit", "shark", "sparrow", "tiger", "wolf"): # s = w.search(q, cached=True) # s = s.plaintext() # print os.path.join("corpus2", q+".txt") # f = codecs.open(os.path.join("corpus2", q+".txt"), "w", encoding="utf-8") # f.write(s) # f.close() # Loading a document from a text file:<|fim▁hole|>print document.keywords(top=10) # (weight, feature)-items. print # Same document, using lemmatization instead of stemming (slower): document = Document(s, name="wolf", stemmer=LEMMA) print document print document.keywords(top=10) print # In summary, a document is a bag-of-words representation of a text. # Bag-of-words means that the word order is discarded. # The dictionary of words (features) and their normalized word count (weights) # is also called the document vector: document = Document("a black cat and a white cat", stopwords=True) print document.words print document.vector.features for feature, weight in document.vector.items(): print feature, weight # Document vectors can be bundled into a Model (next example).<|fim▁end|>
f = os.path.join(os.path.dirname(__file__), "corpus", "wolf.txt") s = codecs.open(f, encoding="utf-8").read() document = Document(s, name="wolf", stemmer=PORTER) print document
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model):<|fim▁hole|> name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu'<|fim▁end|>
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): <|fim_middle|> @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): <|fim_middle|> @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
return self.ip
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): <|fim_middle|> tible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compa
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): <|fim_middle|> class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
return self.name
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: <|fim_middle|> tible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compa
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(ma<|fim_middle|> _digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
x_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name clas<|fim_middle|> verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
s Meta:
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" <|fim_middle|> _digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max