sergzak022 / scrape-smc

1 stars 1 forks source link

Parser tests & parser module breakout #2

Open kfatehi opened 8 years ago

kfatehi commented 8 years ago

Hey Sergey

I am doing some work on scrape-uci (adding the ability to scrape the ICS course listing content, which publishes planned classes beyond that of websoc).

In the process I removed any attempt to parse the pre-req string, since we decided you'll make a module for that. Here are the tests I had for that, which I've extracted. I am pasting it here in case it's useful for the prereq parser module.

For the record, these tests never passed for me because I was unable to implement the parser, but you did!

The fixtures it references are here in case you want to take those courses out and use them as examples against these tests.

var expect = require('chai').expect
var _ = require('lodash');
var courses = require('../../../fixtures/2016-winter-raw-prereq');

describe.skip('prereq parser', function() {
  it("parses reqs for IN4MATX 113", function() {
    var course = _.find(courses, { id: 'In4matx113' })
    var reqs = pp.parse(course.prerequisite)
    expect(reqs).to.deep.eq({
      "type": "exactly",
      "aggregateBy": null,
      "select": 2,
      "elements": [{
        "type": "exactly",
        "aggregateBy": null,
        "elements": [
          "IN4MATX 42",
          "I&C SCI 22",
          "CSE 22",
          "AP COMP SCI AB",
          "I&C SCI 33",
          "CSE 43"
        ],
        "select": 1
      },{
        "type": "exactly",
        "aggregateBy": null,
        "elements": [
          "IN4MATX 43",
          "I&C SCI 52"
        ],
        "select": 1
      }]
    })
  })

  it('parses reqs for In4matx122', function() {
    var course = _.find(courses, { id: 'In4matx122' })
    var reqs = pp.parse(course.prerequisite)
    expect(reqs).to.deep.eq({
      "type": "exactly",
      "aggregateBy": null,
      "select": 2,
      "elements": [{
        "type": "exactly",
        "aggregateBy": null,
        "elements": [
          "I&C SCI 45J",
          "I&C SCI 46",
          "IN4MATX 45"
        ],
        "select": 1
      },{
        "type": "exactly",
        "aggregateBy": null,
        "elements": [
          "IN4MATX 101",
          "COMPSCI 141",
          "CSE 141"
        ],
        "select": 1
      }]
    })
  });

  it('parses reqs for In4matx131', function() {
    var course = _.find(courses, { id: 'In4matx131' })
    var reqs = pp.parse(course.prerequisite)
    return
    expect(reqs).to.deep.eq({
      "type": "exactly",
      "aggregateBy": null,
      "select": 1,
      "elements": [{
        "type": "exactly",
        "aggregateBy": null,
        "elements": [
          "IN4MATX 41",
          "I&C SCI 10",
          "I&C SCI 21",
          "I&C SCI H21",
          "CSE 21",
          "ENGR 10",
          "ENGRMAE 10",
          "EECS 10",
          "I&C SCI 31",
          "CSE 41",
          "AP COMP SCI A",
          "AP COMP SCI AB"
        ],
        "select": 1
      }]
    })
  });
})
sergzak022 commented 8 years ago

Thanks, man!....I'm still working on the front and back ends for the website. When I'm done with that I'll first add SMC support.....Then'll I'm planning to add support for UCI, if it's OK with my boss.

I just found out that UCLA and UCB can not be scraped easily. User have to be logged in to we the class schedule. So the only way to work with those schools is to make them like the App, so that they are willing to open an access for scrapers. :-(

On Fri, Jan 1, 2016 at 5:42 AM, Keyvan Fatehi notifications@github.com wrote:

Hey Sergey

I am doing some work on scrape-uci https://github.com/kfatehi/scrape-uci (adding the ability to scrape the ICS course listing content, which publishes planned classes beyond that of websoc).

In the process I removed any attempt to parse the pre-req string, since we decided you'll make a module for that. Here are the tests I had for that, which I've extracted. I am pasting it here in case it's useful for the prereq parser module.

For the record, these tests never passed for me because I was unable to implement the parser, but you did!

var expect = require('chai').expectvar = require('lodash');var courses = require('../../../fixtures/2016-winter-raw-prereq'); describe.skip('prereq parser', function() { it("parses reqs for IN4MATX 113", function() { var course = .find(courses, { id: 'In4matx113' }) var reqs = pp.parse(course.prerequisite) expect(reqs).to.deep.eq({ "type": "exactly", "aggregateBy": null, "select": 2, "elements": [{ "type": "exactly", "aggregateBy": null, "elements": [ "IN4MATX 42", "I&C SCI 22", "CSE 22", "AP COMP SCI AB", "I&C SCI 33", "CSE 43" ], "select": 1 },{ "type": "exactly", "aggregateBy": null, "elements": [ "IN4MATX 43", "I&C SCI 52" ], "select": 1 }] }) })

it('parses reqs for In4matx122', function() { var course = _.find(courses, { id: 'In4matx122' }) var reqs = pp.parse(course.prerequisite) expect(reqs).to.deep.eq({ "type": "exactly", "aggregateBy": null, "select": 2, "elements": [{ "type": "exactly", "aggregateBy": null, "elements": [ "I&C SCI 45J", "I&C SCI 46", "IN4MATX 45" ], "select": 1 },{ "type": "exactly", "aggregateBy": null, "elements": [ "IN4MATX 101", "COMPSCI 141", "CSE 141" ], "select": 1 }] }) });

it('parses reqs for In4matx131', function() { var course = _.find(courses, { id: 'In4matx131' }) var reqs = pp.parse(course.prerequisite) return expect(reqs).to.deep.eq({ "type": "exactly", "aggregateBy": null, "select": 1, "elements": [{ "type": "exactly", "aggregateBy": null, "elements": [ "IN4MATX 41", "I&C SCI 10", "I&C SCI 21", "I&C SCI H21", "CSE 21", "ENGR 10", "ENGRMAE 10", "EECS 10", "I&C SCI 31", "CSE 41", "AP COMP SCI A", "AP COMP SCI AB" ], "select": 1 }] }) }); })

— Reply to this email directly or view it on GitHub https://github.com/sergzak022/scrape-smc/issues/2.

kfatehi commented 8 years ago

Sounds fair. When you get a moment please check out https://github.com/kfatehi/what-to-take-uci/blob/master/index.js and look at the comments (it's very very short)