Changeset 465 in tmcsimulator for trunk


Ignore:
Timestamp:
07/26/2019 05:12:05 AM (7 years ago)
Author:
jdalbey
Message:

Coordinator.java: Update writeToCAD to sort comments by timestamp instead of incident number. Also add a unit test for this. Fixes #175.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/python/unifiedlogger/wing_project.wpr

    r462 r465  
    183183                       'toolbox-percent': 1.0, 
    184184                       'toolbox-tree-sel': ''})], 
    185         'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('logging_service.py'), 
    186         {'attrib-starts': [('getSimTime|0|', 
    187                             7)], 
    188          'code-line': '       print "Error loading json for elapsed time"\n', 
    189          'first-line': 0L, 
     185        'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('activitylog_watcher.py'), 
     186        {'attrib-starts': [], 
     187         'code-line': '# Local main for unit testing\n', 
     188         'first-line': 48L, 
    190189         'folded-linenos': [], 
    191          'sel-line': 14L, 
    192          'sel-line-start': 410L, 
    193          'selection_end': 460L, 
    194          'selection_start': 460L, 
     190         'sel-line': 50L, 
     191         'sel-line-start': 1431L, 
     192         'selection_end': 1460L, 
     193         'selection_start': 1460L, 
    195194         'zoom': 0L}, 
    196         1563914714.187541], 
    197         [loc('cad_watcher.py'), 
    198          {'attrib-starts': [('isFull|0|', 
    199                              16)], 
    200           'code-line': '\n', 
    201           'first-line': 18L, 
    202           'folded-linenos': [], 
    203           'sel-line': 18L, 
    204           'sel-line-start': 559L, 
    205           'selection_end': 559L, 
    206           'selection_start': 559L, 
    207           'zoom': 0L}, 
    208          1563914983.485065], 
    209         [loc('activitylog_watcher.py'), 
    210          {'attrib-starts': [], 
    211           'code-line': '# Local main for unit testing\n', 
    212           'first-line': 48L, 
    213           'folded-linenos': [], 
    214           'sel-line': 50L, 
    215           'sel-line-start': 1431L, 
    216           'selection_end': 1460L, 
    217           'selection_start': 1460L, 
    218           'zoom': 0L}, 
    219          1563915276.741928], 
     195        1563915276.741928], 
    220196        [loc('../../../../../../../../usr/lib/python2.7/ConfigParser.py'), 
    221197         {'attrib-starts': [('ConfigParser|0|', 
     
    422398          'selection_start': 565L, 
    423399          'zoom': 0L}, 
    424          1563916220.372856]], 
     400         1563916220.372856], 
     401        [loc('activitylog_watcher.py'), 
     402         {'attrib-starts': [('getLogEntries|0|', 
     403                             42)], 
     404          'code-line': '    resultList = []\n', 
     405          'first-line': 40L, 
     406          'folded-linenos': [], 
     407          'sel-line': 48L, 
     408          'sel-line-start': 1422L, 
     409          'selection_end': 1422L, 
     410          'selection_start': 1422L, 
     411          'zoom': 0L}, 
     412         1564099965.745285], 
     413        [loc('cad_watcher.py'), 
     414         {'attrib-starts': [('isFull|0|', 
     415                             16)], 
     416          'code-line': '\n', 
     417          'first-line': 3L, 
     418          'folded-linenos': [], 
     419          'sel-line': 18L, 
     420          'sel-line-start': 559L, 
     421          'selection_end': 559L, 
     422          'selection_start': 559L, 
     423          'zoom': 0L}, 
     424         1564102192.752733]], 
    425425        20), 
    426         'current-loc': loc('activitylog_watcher.py'), 
     426        'current-loc': loc('__main__.py'), 
    427427        'editor-state-list': [(loc('activitylog_watcher.py'), 
    428428                               {'attrib-starts': [('getLogEntries|0|', 
     
    440440        16)], 
    441441                                'code-line': '\n', 
    442                                 'first-line': 18L, 
     442                                'first-line': 3L, 
    443443                                'folded-linenos': [], 
    444444                                'sel-line': 18L, 
     
    500500         loc('__main__.py')]), 
    501501                               'open_files': [u'../../../config/logging_service.cfg', 
    502         u'__main__.py', 
    503         u'cad_watcher.py', 
    504502        u'cms_watcher.py', 
    505503        u'logging_service.py', 
    506         u'activitylog_watcher.py']}, 
     504        u'activitylog_watcher.py', 
     505        u'cad_watcher.py', 
     506        u'__main__.py']}, 
    507507        'saved_notebook_display': None, 
    508508        'split_percents': {0: 0.5}, 
     
    519519                 'traversal_pos': ((0, 
    520520                                    4), 
    521                                    1563917662.000223), 
     521                                   1564102198.163837), 
    522522                 'user_data': {}}, 
    523523        'window-alloc': (29, 
     
    525525                         1197, 
    526526                         722)}]} 
    527 guimgr.recent-documents = [loc('activitylog_watcher.py'), 
     527guimgr.recent-documents = [loc('__main__.py'), 
     528                           loc('cad_watcher.py'), 
     529                           loc('activitylog_watcher.py'), 
    528530                           loc('logging_service.py'), 
    529531                           loc('cms_watcher.py'), 
    530                            loc('__main__.py'), 
    531                            loc('cad_watcher.py'), 
    532532                           loc('../../../config/logging_service.cfg')] 
    533533guimgr.visual-state = {loc('get_app_properties.py'): {'attrib-starts': [], 
  • trunk/src/tmcsim/application.properties

    r463 r465  
    1 #Tue, 23 Jul 2019 14:36:26 -0700 
     1#Fri, 26 Jul 2019 06:34:33 -0700 
    22 
    3 Application.revision=462 
     3Application.revision=464 
    44 
    55Application.buildnumber=170 
  • trunk/src/tmcsim/cadsimulator/Coordinator.java

    r448 r465  
    88import java.text.DateFormat; 
    99import java.text.SimpleDateFormat; 
     10import java.util.ArrayList; 
     11import java.util.Collections; 
    1012import java.util.Date; 
    1113import java.util.LinkedList; 
     14import java.util.List; 
    1215import java.util.Observer; 
    1316import java.util.TreeMap; 
     
    744747            Logger.getLogger(Coordinator.class.getName()).log(Level.SEVERE, null, ex); 
    745748        } 
    746         // Initialize an output buffer 
    747         StringBuffer output = new StringBuffer(); 
     749        // Write output list to a file 
     750        try  
     751        { 
     752            PrintWriter writer = new PrintWriter(new FileWriter(kCADcommentLog)); 
     753            // process the list of comments obtained from helper method 
     754            for (String item: getSortedComments(incList)) 
     755            { 
     756                writer.print(item.substring(9)); 
     757            } 
     758            writer.close(); 
     759        } catch (Exception exc)  
     760        { 
     761            exc.printStackTrace(); 
     762        }  
     763    } 
     764     
     765    /** Extract a list of comments from the current incidents, ordered 
     766     * by timestamp.  Fixes defect #175. 
     767     * Package private to allow unit testing. 
     768     *  
     769     * @param incidentList the incidents from which comments are desired 
     770     * @return list of comments, ready to be output. 
     771     */ 
     772    List<String> getSortedComments(Vector<Incident> incidentList) 
     773    { 
     774        // Initialize a list of for outputing CAD comments 
     775        ArrayList<String> commentList = new ArrayList<String>(); 
    748776        // Process all the incidents 
    749         for (Incident incident: incList) 
     777        for (Incident incident: incidentList) 
    750778        { 
    751779            // Retrieve the table of comments/notes the users created 
     
    755783            { 
    756784                // Combine the fields into one output entry 
     785                String timestamp = (String)notesTable.getValueAt(row,1); 
    757786                String initials = (String) notesTable.getValueAt(row,2); // user initials 
    758787                // If there are user intials, include this item. 
    759788                // Zero length initials mean it's a scripted item, ignore it. 
     789                StringBuffer output = new StringBuffer(); 
    760790                if (initials.length() > 0) 
    761                 {//CAD Log Entry, Incident #187, Sharon: REQUEST EXTRA ANCHOVIES 
    762                     output.append("CAD log, "); 
     791                {//17:03:19 CAD Log Entry, Incident #187, Sharon: REQUEST EXTRA ANCHOVIES 
     792                    output.append(timestamp); 
     793                    output.append(" CAD log, "); 
    763794                    output.append("Incident #" + incident.logNum + ", "); 
    764795                    output.append(initials + ": "); 
    765796                    output.append(notesTable.getValueAt(row,4) + "\n"); // notes 
     797                    commentList.add(output.toString()); // Add this comment to the list 
    766798                } 
    767799            } 
    768800        } 
    769         // Write output buffer to a file 
    770         try  
    771         { 
    772             PrintWriter writer = new PrintWriter(new FileWriter(kCADcommentLog)); 
    773             writer.print(output); 
    774             writer.close(); 
    775         } catch (Exception exc)  
    776         { 
    777             exc.printStackTrace(); 
    778         }  
    779     } 
    780      
     801        // Order the comments by timestamp instead of incident number. 
     802        Collections.sort(commentList, new java.util.Comparator<String>()  
     803        { 
     804            // provide a comparator that can compare number strings 
     805            public int compare(String o1, String o2)  
     806            { 
     807                return extractInt(o1) - extractInt(o2); 
     808            } 
     809            // extract an integer from a String     
     810            int extractInt(String s)  
     811            {   // remove all non-digits 
     812                String num = s.replaceAll("\\D", ""); 
     813                // return 0 if no digits found, else return the number 
     814                return num.isEmpty() ? 0 : Integer.parseInt(num); 
     815            } 
     816        }); 
     817        return commentList; 
     818    } 
    781819    /** Write the currentSimTime to a file.  
    782820       This will be read asynchronously by web clients, e.g., 
Note: See TracChangeset for help on using the changeset viewer.