Changeset 32616 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-07-08T22:37:38+02:00 (8 years ago)
Author:
darya
Message:

Solitary stop position test

Location:
applications/editors/josm/plugins/pt_assistant
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java

    r32603 r32616  
    173173                return false;
    174174        }
     175       
     176        /**
     177         * Checks if the type of the way is suitable for buses to go on it. The
     178         * direction of the way (i.e. one-way roads) is irrelevant for this test.
     179         *
     180         * @param way
     181         *            to be checked
     182         * @return true if the way is suitable for buses, false otherwise.
     183         */
     184        public static boolean isWaySuitableForBuses(Way way) {
     185                if (way.hasTag("highway", "motorway") || way.hasTag("highway", "trunk") || way.hasTag("highway", "primary")
     186                                || way.hasTag("highway", "secondary") || way.hasTag("highway", "tertiary")
     187                                || way.hasTag("highway", "unclassified") || way.hasTag("highway", "road")
     188                                || way.hasTag("highway", "residential") || way.hasTag("highway", "service")
     189                                || way.hasTag("highway", "motorway_link") || way.hasTag("highway", "trunk_link")
     190                                || way.hasTag("highway", "primary_link") || way.hasTag("highway", "secondary_link")
     191                                || way.hasTag("highway", "tertiary_link") || way.hasTag("highway", "living_street")
     192                                || way.hasTag("highway", "bus_guideway") || way.hasTag("highway", "road")
     193                                || way.hasTag("cycleway", "share_busway") || way.hasTag("cycleway", "shared_lane")) {
     194                        return true;
     195                }
     196
     197                if (way.hasTag("highway", "pedestrian") && (way.hasTag("bus", "yes") || way.hasTag("psv", "yes")
     198                                || way.hasTag("bus", "designated") || way.hasTag("psv", "designated"))) {
     199                        return true;
     200                }
     201
     202                return false;
     203        }
    175204
    176205}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/Checker.java

    r32597 r32616  
    44import java.util.List;
    55
     6import org.openstreetmap.josm.data.osm.Node;
    67import org.openstreetmap.josm.data.osm.Relation;
    78import org.openstreetmap.josm.data.osm.RelationMember;
     
    2021        // test which created this WayChecker:
    2122        protected final Test test;
     23       
     24        // node that is checked:
     25        protected Node node;
    2226
    2327        // relation that is checked:
     
    2630        // stores all found errors:
    2731        protected ArrayList<TestError> errors = new ArrayList<>();
     32       
     33        protected Checker(Node node, Test test) {
     34                this.node = node;
     35                this.test = test;
     36        }
    2837
    2938        protected Checker(Relation relation, Test test) {
    30 
    3139                this.relation = relation;
    3240                this.test = test;
    33 
    3441        }
    3542
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java

    r32567 r32616  
    1313import org.openstreetmap.josm.command.SequenceCommand;
    1414import org.openstreetmap.josm.data.osm.DataSet;
     15import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.Relation;
    1617import org.openstreetmap.josm.data.validation.Severity;
    1718import org.openstreetmap.josm.data.validation.Test;
    1819import org.openstreetmap.josm.data.validation.TestError;
     20import org.openstreetmap.josm.plugins.pt_assistant.actions.DownloadReferrersThread;
    1921import org.openstreetmap.josm.plugins.pt_assistant.actions.FixTask;
    2022import org.openstreetmap.josm.plugins.pt_assistant.actions.IncompleteMembersDownloadThread;
     23import org.openstreetmap.josm.plugins.pt_assistant.gui.DownloadReferrersDialog;
    2124import org.openstreetmap.josm.plugins.pt_assistant.gui.IncompleteMembersDownloadDialog;
    2225import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer;
     
    3033        public static final int ERROR_CODE_CONSTRUCTION = 3722;
    3134        public static final int ERROR_CODE_DIRECTION = 3731;
    32         public static final int ERROR_CODE_END_STOP = 3141;
    33         public static final int ERROR_CODE_SPLIT_WAY = 3142;
    34         public static final int ERROR_CODE_RELAITON_MEMBER_ROLES = 3143;
     35        public static final int ERROR_CODE_END_STOP = 3741;
     36        public static final int ERROR_CODE_SPLIT_WAY = 3742;
     37        public static final int ERROR_CODE_RELAITON_MEMBER_ROLES = 3743;
     38        public static final int ERROR_CODE_SOLITARY_STOP_POSITION = 3751;
     39        public static final int ERROR_CODE_PLATFORM_PART_OF_HIGHWAY = 3752;
    3540
    3641        private PTAssistantLayer layer;
     42        private static boolean nodeReferrersDownloaded;
     43        @SuppressWarnings("unused")
     44        private static boolean incompleteRelationsDowloaded;
     45
    3746
    3847        public PTAssistantValidatorTest() {
     
    4251                layer = new PTAssistantLayer();
    4352                DataSet.addSelectionListener(layer);
     53                nodeReferrersDownloaded = false;
     54                incompleteRelationsDowloaded = false;
     55
     56        }
     57
     58        @Override
     59        public void visit(Node n) {
     60
     61                if (n.isIncomplete()) {
     62                        return;
     63                }
     64
     65                if (!nodeReferrersDownloaded) {
     66                        this.downloadReferrers(n);
     67                        nodeReferrersDownloaded = true;
     68                }
     69
     70                NodeChecker nodeChecker = new NodeChecker(n, this);
     71
     72                // check for solitary stop positions:
     73                if (n.hasTag("public_transport", "stop_position")) {
     74                        nodeChecker.performSolitaryStopPositionTest();
     75                }
     76
     77                // check that platforms are not part of any way:
     78                if (n.hasTag("highway", "bus_stop") || n.hasTag("public_transport", "platform")
     79                                || n.hasTag("highway", "platform") || n.hasTag("railway", "platform")) {
     80                        nodeChecker.performPlatformPartOfWayTest();
     81                }
     82               
     83                this.errors.addAll(nodeChecker.getErrors());
     84
     85        }
     86       
     87
     88        /**
     89         * Downloads incomplete relation members in an extra thread (user input
     90         * required)
     91         *
     92         * @return true if successful, false if not successful
     93         */
     94        private boolean downloadReferrers(Node n) {
     95
     96                final int[] userSelection = { 0 };
     97
     98                try {
     99
     100                        if (SwingUtilities.isEventDispatchThread()) {
     101
     102                                userSelection[0] = showDownloadReferrersDialog();
     103
     104                        } else {
     105
     106                                SwingUtilities.invokeAndWait(new Runnable() {
     107                                        @Override
     108                                        public void run() {
     109                                                try {
     110                                                        userSelection[0] = showDownloadReferrersDialog();
     111                                                } catch (InterruptedException e) {
     112                                                        e.printStackTrace();
     113                                                }
     114
     115                                        }
     116                                });
     117
     118                        }
     119
     120                } catch (InterruptedException | InvocationTargetException e) {
     121                        return false;
     122                }
     123
     124                if (userSelection[0] == JOptionPane.YES_OPTION) {
     125
     126                        Thread t = new DownloadReferrersThread(n);
     127                        t.start();
     128                        synchronized (t) {
     129                                try {
     130                                        t.wait();
     131                                } catch (InterruptedException e) {
     132                                        return false;
     133                                }
     134                        }
     135
     136                }
     137
     138                return true;
     139
     140        }
     141
     142        /**
     143         * Shows the dialog asking the user about an incomplete member download
     144         *
     145         * @return user's selection
     146         * @throws InterruptedException
     147         */
     148        private int showDownloadReferrersDialog() throws InterruptedException {
     149
     150                DownloadReferrersDialog downloadReferrersDialog = new DownloadReferrersDialog();
     151                return downloadReferrersDialog.getUserSelection();
    44152
    45153        }
     
    55163                // and do not do any testing.
    56164                if (r.hasIncompleteMembers()) {
    57 
     165                       
    58166                        boolean downloadSuccessful = this.downloadIncompleteMembers();
    59167                        if (!downloadSuccessful) {
    60168                                return;
    61169                        }
     170                        incompleteRelationsDowloaded = true;
    62171
    63172                }
     
    313422                }
    314423
     424                if (testError.getCode() == ERROR_CODE_SOLITARY_STOP_POSITION) {
     425                        // TODO
     426                }
     427
    315428                if (commands.isEmpty()) {
    316429                        return null;
     
    357470                                new TestError(this, Severity.WARNING, tr("PT: dummy test warning"), ERROR_CODE_DIRECTION, primitives));
    358471        }
     472       
     473    public void endTest() {
     474        super.endTest();
     475        nodeReferrersDownloaded = false;
     476        incompleteRelationsDowloaded = false;
     477    }
    359478
    360479}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java

    r32603 r32616  
    6262                                boolean isCorrectRoadType = true;
    6363                                boolean isUnderConstruction = false;
     64                                if (way.hasKey("construction")) {
     65                                        isUnderConstruction = true;
     66                                }
    6467                                if (relation.hasTag("route", "bus") || relation.hasTag("route", "share_taxi")) {
    65                                         if (!isWaySuitableForBuses(way)) {
    66                                                 isCorrectRoadType = false;
    67                                         }
    68                                         if (way.hasTag("highway", "construction") && way.hasKey("construction")) {
     68                                        if (!RouteUtils.isWaySuitableForBuses(way)) {
     69                                                isCorrectRoadType = false;
     70                                        }
     71                                        if (way.hasTag("highway", "construction")) {
    6972                                                isUnderConstruction = true;
    7073                                        }
    7174                                } else if (relation.hasTag("route", "trolleybus")) {
    72                                         if (!(isWaySuitableForBuses(way) && way.hasTag("trolley_wire", "yes"))) {
    73                                                 isCorrectRoadType = false;
    74                                         }
    75                                         if (way.hasTag("highway", "construction") && way.hasKey("construction")) {
     75                                        if (!(RouteUtils.isWaySuitableForBuses(way) && way.hasTag("trolley_wire", "yes"))) {
     76                                                isCorrectRoadType = false;
     77                                        }
     78                                        if (way.hasTag("highway", "construction")) {
    7679                                                isUnderConstruction = true;
    7780                                        }
     
    8083                                                isCorrectRoadType = false;
    8184                                        }
    82                                         if (way.hasTag("railway", "construction") && way.hasKey("construction")) {
     85                                        if (way.hasTag("railway", "construction")) {
    8386                                                isUnderConstruction = true;
    8487                                        }
     
    8790                                                isCorrectRoadType = false;
    8891                                        }
    89                                         if (way.hasTag("railway", "construction") && way.hasKey("construction")) {
     92                                        if (way.hasTag("railway", "construction")) {
    9093                                                isUnderConstruction = true;
    9194                                        }
     
    9497                                                isCorrectRoadType = false;
    9598                                        }
    96                                         if (way.hasTag("railway", "construction") && way.hasKey("construction")) {
     99                                        if (way.hasTag("railway", "construction")) {
    97100                                                isUnderConstruction = true;
    98101                                        }
     
    101104                                                isCorrectRoadType = false;
    102105                                        }
    103                                         if (way.hasTag("railway", "construction") && way.hasKey("construction")) {
     106                                        if (way.hasTag("railway", "construction")) {
    104107                                                isUnderConstruction = true;
    105108                                        }
     
    108111                                                isCorrectRoadType = false;
    109112                                        }
    110                                         if (way.hasTag("railway", "construction") && way.hasKey("construction")) {
     113                                        if (way.hasTag("railway", "construction")) {
    111114                                                isUnderConstruction = true;
    112115                                        }
     
    198201                        // highlighted.add(problematicWay);
    199202                        Set<Way> adjacentWays = checkAdjacentWays(problematicWay, new HashSet<Way>());
     203                        adjacentWays.removeAll(problematicWays);       
     204                        highlighted.add(problematicWay);
    200205                        highlighted.addAll(adjacentWays);
    201206                        TestError e = new TestError(this.test, Severity.WARNING,
     
    371376        }
    372377
    373         /**
    374          * Checks if the type of the way is suitable for buses to go on it. The
    375          * direction of the way (i.e. one-way roads) is irrelevant for this test.
    376          *
    377          * @param way
    378          *            to be checked
    379          * @return true if the way is suitable for buses, false otherwise.
    380          */
    381         private boolean isWaySuitableForBuses(Way way) {
    382                 if (way.hasTag("highway", "motorway") || way.hasTag("highway", "trunk") || way.hasTag("highway", "primary")
    383                                 || way.hasTag("highway", "secondary") || way.hasTag("highway", "tertiary")
    384                                 || way.hasTag("highway", "unclassified") || way.hasTag("highway", "road")
    385                                 || way.hasTag("highway", "residential") || way.hasTag("highway", "service")
    386                                 || way.hasTag("highway", "motorway_link") || way.hasTag("highway", "trunk_link")
    387                                 || way.hasTag("highway", "primary_link") || way.hasTag("highway", "secondary_link")
    388                                 || way.hasTag("highway", "tertiary_link") || way.hasTag("highway", "living_street")
    389                                 || way.hasTag("highway", "bus_guideway") || way.hasTag("highway", "road")
    390                                 || way.hasTag("cycleway", "share_busway") || way.hasTag("cycleway", "shared_lane")) {
    391                         return true;
    392                 }
    393 
    394                 if (way.hasTag("highway", "pedestrian") && (way.hasTag("bus", "yes") || way.hasTag("psv", "yes")
    395                                 || way.hasTag("bus", "designated") || way.hasTag("psv", "designated"))) {
    396                         return true;
    397                 }
    398 
    399                 return false;
    400         }
    401 
    402378        protected static Command fixErrorByRemovingWay(TestError testError) {
    403379
  • applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/AbstractTest.java

    r32603 r32616  
    4444 public static final String PATH_TO_ONEWAY_WRONG_DIRECTION = "test/data/oneway-wrong-direction.osm";
    4545 public static final String PATH_TO_ONEWAY_WRONG_DIRECTION2 = "test/data/oneway-wrong-direction2.osm";
     46 
     47 public static final String PATH_TO_SOLITARY_STOP_POSITION = "test/data/solitary-stop-position.osm";
    4648
    4749  /**
  • applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/DirecionTestTest.java

    r32603 r32616  
    1717
    1818public class DirecionTestTest extends AbstractTest {
    19    
    20     @Test
    21     public void testOnewayTrue() {
    22        
    23         File file = new File(AbstractTest.PATH_TO_ONEWAY_WRONG_DIRECTION);
    24         DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
    25        
    26         PTAssistantValidatorTest test = new PTAssistantValidatorTest();
    27        
    28         Relation route = null;
    29         for (Relation r: ds.getRelations()) {
    30             if (r.hasKey("route")) {
    31                 route = r;
    32             }
    33         }
    34        
    35              
    36         List<TestError> errors = new ArrayList<>();
    37        
    38         for (Relation r: ds.getRelations()) {
    39                 WayChecker wayChecker = new WayChecker(r, test);
    40                 wayChecker.performDirectionTest();
    41                 errors.addAll(wayChecker.getErrors());
    42         }
    43        
    44         assertEquals(errors.size(), 2);
    45         int onewayErrorCaught = 0;
    46         for (TestError e: errors ) {
    47             if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) {
    48                 onewayErrorCaught++;
    49             }
    50         }
    51        
    52         assertEquals(onewayErrorCaught, 2);
    53        
    54         // fix the direction errors:
    55        
    56         boolean detectedErrorsAreCorrect = true;
    57         for (TestError e: errors) {
    58             if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) {
    59                 @SuppressWarnings("unchecked")
    60                 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted();
    61                 if (highlighted.get(0).getId() != 225732678 && highlighted.get(0).getId() != 24215210)  {
    62                     detectedErrorsAreCorrect = false;
    63                 }
    64             }
    65         }
    66        
    67         assertTrue(detectedErrorsAreCorrect);
    68     }
     19
     20        @Test
     21        public void testOnewayTrue() {
     22
     23                File file = new File(AbstractTest.PATH_TO_ONEWAY_WRONG_DIRECTION);
     24                DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
     25
     26                PTAssistantValidatorTest test = new PTAssistantValidatorTest();
     27
     28                List<TestError> errors = new ArrayList<>();
     29
     30                for (Relation r : ds.getRelations()) {
     31                        WayChecker wayChecker = new WayChecker(r, test);
     32                        wayChecker.performDirectionTest();
     33                        errors.addAll(wayChecker.getErrors());
     34                }
     35
     36                assertEquals(errors.size(), 2);
     37                int onewayErrorCaught = 0;
     38                for (TestError e : errors) {
     39                        if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) {
     40                                onewayErrorCaught++;
     41                        }
     42                }
     43
     44                assertEquals(onewayErrorCaught, 2);
     45
     46                // fix the direction errors:
     47
     48                boolean detectedErrorsAreCorrect = true;
     49                for (TestError e : errors) {
     50                        if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) {
     51                                @SuppressWarnings("unchecked")
     52                                List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted();
     53                                if (highlighted.get(0).getId() != 225732678 && highlighted.get(0).getId() != 24215210) {
     54                                        detectedErrorsAreCorrect = false;
     55                                }
     56                        }
     57                }
     58
     59                assertTrue(detectedErrorsAreCorrect);
     60        }
    6961}
Note: See TracChangeset for help on using the changeset viewer.