brumbrum

Challenge 2

Speed Runs: optimising truck payload and cycle speeds

Description

Challenge Statement

At the Cowal Gold Mine, trucks transport ore over many km’s from the open pit. The more ore they take, the slower they move. Can you optimise for speed and tonnage?

Background

The Cowal operation is an open pit mining operation with production from a number of different areas within a large, single pit. As a result of the general site configuration and layout, haul distances, in particular for waste disposal, is the longest of all open pit operations across the company. Material is typically hauled for a 4km distance at a 1:10 incline and thereafter another 1-3km on a reasonably flat surface to the crusher, stockpiles or waste rock dumps depending on material type. A fleet monitoring system (MineStar) is installed and fully operational with a significant amount of individual truck cycle data available. Mining is carried out with a company-owned fleet of mining equipment that includes 2 x Liebherr 994 backhoe excavators, 1 x Hitachi 3600 Excavator and 16 x Cat 789 dump trucks. The Challenge

The key question remains: What is the optimum payload vs haul speed trade-off and how does that change with increases to the depth of the pit and haulage distances to future waste dump locations? The Opportunity

At present the operating philosophy is to “light load” trucks to ensure they reach at least second gear on the way out on the ramp. Payloads are controlled, however given the haul distance required, every tonne counts. If the optimum cycle speeds and payload can be determined, there is potential to improve productivity and reduce costs across the haulage fleet. Considerations

Critical areas to consider include:

For any given haulage cycle, can payload be “calibrated” to a specific location using historical VIMS data?
In excess of two years VIMS data is available for analysis that could be “mined” to establish the optimum trade-off!
Can payload optimisation be done in real time and displayed to the operator?

Data Summary

TBC Mentors

Ryan Kare - Lead Mentor

Elam Athimoolam

In [153]:
import pandas
import json
In [ ]:
 
In [ ]:
 
In [154]:
pitconf = pandas.read_excel('/home/wcmckee/data/Truck_Spec.xlsx', sheetname='SiteInfo', index_col='Parameter')
In [155]:
rimpulldata = pandas.read_excel('/home/wcmckee/data/Truck_Spec.xlsx', sheetname='Rimpull')
In [156]:
print(rimpulldata)
    Speed (km)   Force (kgf)
0     0.000000  85124.846100
1     1.269841  84181.974090
2     2.116402  81415.558050
3     3.386243  75308.980180
4     4.444444  69660.426470
5     5.291005  63721.832620
6     6.137566  58289.507510
7     6.984127  52729.697590
8     7.407407  50432.017810
9     8.465608  49811.731730
10    8.982951  48895.577950
11    9.805996  46534.040820
12   10.370370  43904.562710
13   10.793651  41372.434300
14   11.005291  39471.824240
15   11.216931  36920.178720
16   11.851852  36511.238150
17   12.275132  36106.827140
18   13.004115  35050.162540
19   13.474427  34278.007420
20   13.874192  33398.632820
21   14.203410  32461.371820
22   15.026455  29657.294330
23   15.238095  28718.205310
24   15.449735  27331.186050
25   16.084656  27028.456450
26   16.507937  26729.079990
27   17.330982  26043.367020
28   19.776602  23413.949310
29   20.129336  22756.887040
..         ...           ...
32   21.375661  20232.668330
33   22.433862  19786.942620
34   24.126984  18924.732900
35   25.396825  18100.093690
36   27.231041  16701.106460
37   27.654321  16292.804100
38   27.889477  15796.434640
39   28.148148  14977.793750
40   29.417989  14811.894570
41   30.264550  14647.832940
42   32.169312  14166.470980
43   34.074074  13549.171520
44   35.978836  12815.234900
45   37.037037  12394.096380
46   37.671958  11986.797470
47   37.883598  11722.728300
48   38.095238  11211.914150
49   39.788360  11087.727140
50   41.269841  10964.915670
51   42.962963  10723.358560
52   44.232804  10487.122960
53   48.583186   9522.120346
54   50.229277   9073.447255
55   50.723104   8895.549731
56   52.204586   8007.331433
57   53.380364   6893.723843
58   54.673721   5725.762322
59   54.861846   5186.037841
60   55.097002   4249.158596
61   55.261611   3848.622425

[62 rows x 2 columns]
In [114]:
rimpulldata
Out[114]:
Speed (km) Force (kgf)
0 0.000000 85124.846100
1 1.269841 84181.974090
2 2.116402 81415.558050
3 3.386243 75308.980180
4 4.444444 69660.426470
5 5.291005 63721.832620
6 6.137566 58289.507510
7 6.984127 52729.697590
8 7.407407 50432.017810
9 8.465608 49811.731730
10 8.982951 48895.577950
11 9.805996 46534.040820
12 10.370370 43904.562710
13 10.793651 41372.434300
14 11.005291 39471.824240
15 11.216931 36920.178720
16 11.851852 36511.238150
17 12.275132 36106.827140
18 13.004115 35050.162540
19 13.474427 34278.007420
20 13.874192 33398.632820
21 14.203410 32461.371820
22 15.026455 29657.294330
23 15.238095 28718.205310
24 15.449735 27331.186050
25 16.084656 27028.456450
26 16.507937 26729.079990
27 17.330982 26043.367020
28 19.776602 23413.949310
29 20.129336 22756.887040
... ... ...
32 21.375661 20232.668330
33 22.433862 19786.942620
34 24.126984 18924.732900
35 25.396825 18100.093690
36 27.231041 16701.106460
37 27.654321 16292.804100
38 27.889477 15796.434640
39 28.148148 14977.793750
40 29.417989 14811.894570
41 30.264550 14647.832940
42 32.169312 14166.470980
43 34.074074 13549.171520
44 35.978836 12815.234900
45 37.037037 12394.096380
46 37.671958 11986.797470
47 37.883598 11722.728300
48 38.095238 11211.914150
49 39.788360 11087.727140
50 41.269841 10964.915670
51 42.962963 10723.358560
52 44.232804 10487.122960
53 48.583186 9522.120346
54 50.229277 9073.447255
55 50.723104 8895.549731
56 52.204586 8007.331433
57 53.380364 6893.723843
58 54.673721 5725.762322
59 54.861846 5186.037841
60 55.097002 4249.158596
61 55.261611 3848.622425

62 rows × 2 columns

In [151]:
def createtruckspec(truckid, trucktype, emptyweight, maxoperatingweight):
    return({'truckid' : truckid, 'TruckType' : trucktype, 'EmptyWeight' : emptyweight, 'maxoperatingweight' : maxoperatingweight})
In [152]:
createtruckspec(450, "789C", 114114, 317514.85)
Out[152]:
{'EmptyWeight': 114114,
 'TruckType': '789C',
 'maxoperatingweight': 317514.85,
 'truckid': 450}
In [ ]:
 
In [ ]:
@app.route('/getruckspec')
def getruckspec():
    # give it truck id and returns back stats about that truck.
    # todo: return back truck segment details also. 
    #localhost:5555/getruckspec?truckid=410
    #returns back:
    #{"EmptyWeight": 124114, "MaxOperatingWeight": 317514.85, "TruckType": "789C"}
    truckid = request.args.get('truckid')
    #truckid = request.args.get("truckid")
    
    return(jsonify({'truckid' : truckid, 'EmptyWeight' : truckdicspec['EmptyWeight'][truckid],
        'MaxOperatingWeight' : truckdicspec['MaxOperatingWeight'][truckid], 'TruckType' : truckdicspec['TruckType'][truckid]}))
In [104]:
with open('/home/wcmckee/rimpulldata.json', 'w') as rimwr:
    rimwr.write(rimpulldata.to_json())
In [123]:
with open('/home/wcmckee/rimpulldata.json', 'r') as rimrd:
    rimrda = (rimrd.read())
In [133]:
forjs = json.loads(rimrda)
In [135]:
forjs['Speed (km)']['12']
Out[135]:
10.37037037
In [139]:
forjs['Force (kgf)']['12']
Out[139]:
43904.56271
In [ ]:
 
In [ ]:
 
In [145]:
def lookrimid(rimid):
    
    return({ 'speed' : forjs['Speed (km)'][str(rimid)], 'force' : forjs['Force (kgf)'][str(rimid)], 'id' : rimid})
In [146]:
lookrimid(12)
Out[146]:
{'force': 43904.56271, 'id': 12, 'speed': 10.37037037}
In [148]:
with open('/home/wcmckee/rimpulldata.json', 'r') as rimrd:
    rimjsconv = (rimrd.read())
          
forjs = json.loads(rimjsconv)
In [150]:
forjs['Force (kgf)']
Out[150]:
{'0': 85124.8461,
 '1': 84181.97409,
 '10': 48895.57795,
 '11': 46534.04082,
 '12': 43904.56271,
 '13': 41372.4343,
 '14': 39471.82424,
 '15': 36920.17872,
 '16': 36511.23815,
 '17': 36106.82714,
 '18': 35050.16254,
 '19': 34278.00742,
 '2': 81415.55805,
 '20': 33398.63282,
 '21': 32461.37182,
 '22': 29657.2943299999,
 '23': 28718.2053099999,
 '24': 27331.18605,
 '25': 27028.4564499999,
 '26': 26729.07999,
 '27': 26043.36702,
 '28': 23413.94931,
 '29': 22756.88704,
 '3': 75308.98018,
 '30': 22063.58565,
 '31': 20459.28236,
 '32': 20232.66833,
 '33': 19786.94262,
 '34': 18924.7329,
 '35': 18100.09369,
 '36': 16701.10646,
 '37': 16292.8041,
 '38': 15796.43464,
 '39': 14977.79375,
 '4': 69660.42647,
 '40': 14811.89457,
 '41': 14647.83294,
 '42': 14166.4709799999,
 '43': 13549.17152,
 '44': 12815.2349,
 '45': 12394.09638,
 '46': 11986.79747,
 '47': 11722.7283,
 '48': 11211.91415,
 '49': 11087.72714,
 '5': 63721.83262,
 '50': 10964.91567,
 '51': 10723.35856,
 '52': 10487.12296,
 '53': 9522.120346,
 '54': 9073.447255,
 '55': 8895.549731,
 '56': 8007.331433,
 '57': 6893.723843,
 '58': 5725.762322,
 '59': 5186.037841,
 '6': 58289.50751,
 '60': 4249.158596,
 '61': 3848.622425,
 '7': 52729.69759,
 '8': 50432.01781,
 '9': 49811.73173}
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [137]:
lookrimid(12)
Out[137]:
10.37037037
In [ ]:
 
In [ ]:
 
In [129]:
print(forjs['Speed (km)'])
{'23': 15.23809524, '30': 20.36449148, '32': 21.37566138, '14': 11.00529101, '4': 4.444444444, '15': 11.21693122, '5': 5.291005291, '12': 10.37037037, '47': 37.88359788, '45': 37.03703704, '51': 42.96296296, '6': 6.137566138, '3': 3.386243386, '61': 55.26161082, '59': 54.86184597, '38': 27.88947678, '25': 16.08465608, '1': 1.26984127, '39': 28.14814815, '0': 0.0, '10': 8.982951205, '34': 24.12698413, '50': 41.26984127, '19': 13.47442681, '49': 39.78835979, '21': 14.20340976, '41': 30.26455026, '24': 15.44973545, '31': 20.74074074, '7': 6.984126984, '58': 54.67372134, '44': 35.97883598, '43': 34.07407407, '37': 27.65432099, '48': 38.0952381, '28': 19.776602, '57': 53.38036449, '53': 48.58318636, '55': 50.72310406, '11': 9.805996473, '20': 13.87419165, '2': 2.116402116, '46': 37.67195767, '35': 25.3968254, '27': 17.33098178, '60': 55.09700176, '26': 16.50793651, '8': 7.407407407, '36': 27.23104056, '54': 50.2292769, '16': 11.85185185, '56': 52.20458554, '18': 13.00411523, '29': 20.12933568, '9': 8.465608466, '33': 22.43386243, '22': 15.02645503, '13': 10.79365079, '52': 44.23280423, '40': 29.41798942, '42': 32.16931217, '17': 12.27513228}
In [ ]:
 
In [ ]:
 
In [125]:
rimrda
Out[125]:
'{"Speed (km)":{"0":0.0,"1":1.26984127,"2":2.116402116,"3":3.386243386,"4":4.444444444,"5":5.291005291,"6":6.137566138,"7":6.984126984,"8":7.407407407,"9":8.465608466,"10":8.982951205,"11":9.805996473,"12":10.37037037,"13":10.79365079,"14":11.00529101,"15":11.21693122,"16":11.85185185,"17":12.27513228,"18":13.00411523,"19":13.47442681,"20":13.87419165,"21":14.20340976,"22":15.02645503,"23":15.23809524,"24":15.44973545,"25":16.08465608,"26":16.50793651,"27":17.33098178,"28":19.776602,"29":20.12933568,"30":20.36449148,"31":20.74074074,"32":21.37566138,"33":22.43386243,"34":24.12698413,"35":25.3968254,"36":27.23104056,"37":27.65432099,"38":27.88947678,"39":28.14814815,"40":29.41798942,"41":30.26455026,"42":32.16931217,"43":34.07407407,"44":35.97883598,"45":37.03703704,"46":37.67195767,"47":37.88359788,"48":38.0952381,"49":39.78835979,"50":41.26984127,"51":42.96296296,"52":44.23280423,"53":48.58318636,"54":50.2292769,"55":50.72310406,"56":52.20458554,"57":53.38036449,"58":54.67372134,"59":54.86184597,"60":55.09700176,"61":55.26161082},"Force (kgf)":{"0":85124.8461,"1":84181.97409,"2":81415.55805,"3":75308.98018,"4":69660.42647,"5":63721.83262,"6":58289.50751,"7":52729.69759,"8":50432.01781,"9":49811.73173,"10":48895.57795,"11":46534.04082,"12":43904.56271,"13":41372.4343,"14":39471.82424,"15":36920.17872,"16":36511.23815,"17":36106.82714,"18":35050.16254,"19":34278.00742,"20":33398.63282,"21":32461.37182,"22":29657.2943299999,"23":28718.2053099999,"24":27331.18605,"25":27028.4564499999,"26":26729.07999,"27":26043.36702,"28":23413.94931,"29":22756.88704,"30":22063.58565,"31":20459.28236,"32":20232.66833,"33":19786.94262,"34":18924.7329,"35":18100.09369,"36":16701.10646,"37":16292.8041,"38":15796.43464,"39":14977.79375,"40":14811.89457,"41":14647.83294,"42":14166.4709799999,"43":13549.17152,"44":12815.2349,"45":12394.09638,"46":11986.79747,"47":11722.7283,"48":11211.91415,"49":11087.72714,"50":10964.91567,"51":10723.35856,"52":10487.12296,"53":9522.120346,"54":9073.447255,"55":8895.549731,"56":8007.331433,"57":6893.723843,"58":5725.762322,"59":5186.037841,"60":4249.158596,"61":3848.622425}}'
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [121]:
for putf in pitconf.values:
    print(putf)
['60 km/h' nan]
['15.7 km/h' 'Locked in 2nd gear']
['28.7 km/h ' 'Locked in 4th gear']
['35 tonnes' nan]
['33.8 sec' 'Time taken to load a bucket']
['30 sec' 'Time to load first bucket']
['30 sec' 'Time taken to reverse under a loader']
['45 sec' nan]
In [ ]:
 
In [118]:
print(pitconf)
                                      Value  \
Parameter                                     
Max Speed Limit                     60 km/h   
Downhill Speed Limit - Loaded     15.7 km/h   
Downhill Speed Limit - Unloaded  28.7 km/h    
Loader bucket capacity            35 tonnes   
Loader cycle time                  33.8 sec   
First loader pass                    30 sec   
Truck spot time at loader            30 sec   
Dump time                            45 sec   

                                                             Comments  
Parameter                                                              
Max Speed Limit                                                   NaN  
Downhill Speed Limit - Loaded                      Locked in 2nd gear  
Downhill Speed Limit - Unloaded                    Locked in 4th gear  
Loader bucket capacity                                            NaN  
Loader cycle time                         Time taken to load a bucket  
First loader pass                           Time to load first bucket  
Truck spot time at loader        Time taken to reverse under a loader  
Dump time                                                         NaN  
In [ ]:
 
In [95]:
import json
In [ ]:
 
In [96]:
with open('/home/wcmckee/pitconfig.json', 'w') as pitw:
    pitw.write(pitconf.to_json())
In [97]:
with open('/home/wcmckee/pitconfig.json', 'r') as pitr:
    pitjs = pitr.read()
    pitlo = json.loads(pitjs)
    
In [98]:
print(pitlo)
{'Comments': {'Downhill Speed Limit - Loaded': 'Locked in 2nd gear', 'Downhill Speed Limit - Unloaded': 'Locked in 4th gear', 'Dump time': None, 'First loader pass': 'Time to load first bucket', 'Truck spot time at loader': 'Time taken to reverse under a loader', 'Max Speed Limit': None, 'Loader bucket capacity': None, 'Loader cycle time': 'Time taken to load a bucket'}, 'Value': {'Downhill Speed Limit - Loaded': '15.7 km/h', 'Downhill Speed Limit - Unloaded': '28.7 km/h ', 'Dump time': '45 sec', 'First loader pass': '30 sec', 'Truck spot time at loader': '30 sec', 'Max Speed Limit': '60 km/h', 'Loader bucket capacity': '35 tonnes', 'Loader cycle time': '33.8 sec'}}
In [88]:
pitlo.keys()
Out[88]:
dict_keys(['Comments', 'Value', 'Parameter'])
In [92]:
for pitl in pitlo.values():
    print(pitl['1'])
Locked in 2nd gear
15.7 km/h
Downhill Speed Limit - Loaded
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
truk= pandas.read_excel('/home/wcmckee/data/Truck_Spec.xlsx', index_col='Truckid')
In [ ]:
 
In [ ]:
print(truk)
In [ ]:
with open('/home/wcmckee/truckspec.json', 'w') as truc:
    truc.write(truk.to_json())
In [ ]:
cat /home/wcmckee/truckspec.json
In [ ]:
with open('/home/wcmckee/truckspec.json', 'r') as truatm:
    tread = truatm.read()
    #print(truatm.read())
In [ ]:
truckdicspec = json.loads(tread)
In [ ]:
 
In [ ]:
truckdicspec
In [ ]:
truckdicspec['TruckType']['418']
In [ ]:
def gettruck(truckid):
           with open('/home/wcmckee/truckspec.json', 'r') as truatm:
               tread = truatm.read()
           truckdicspec = json.loads(tread)
           return({'EmptyWeight' : truckdicspec['EmptyWeight'][truckid],
        'MaxOperatingWeight' : truckdicspec['MaxOperatingWeight'][truckid], 'TruckType' : truckdicspec['TruckType'][truckid]})
In [ ]:
gettruck('410')
In [ ]:
import json
In [ ]:
tred = json.loads(trurd.read())
In [ ]:
#create database of trucks from existing file. 
In [ ]:
somedict = dict()
In [ ]:
somedict.update({truk['Truck ID'] : dict({'test' : 'this is test'})})
In [ ]:
 
In [ ]:
for truk['Truck ID'] in truk:
    print(truk['Truck ID'])
In [ ]:
 
In [ ]:
 
In [ ]:
truk.values
In [ ]:
truk.keys()
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
with open('/home/wcmckee/truckspec.json', 'r') as trurd:
    #print(trurd.read())
    tred = json.loads(trurd.read())
    print(tred)
    
In [ ]:
import sqlite3
In [ ]:
connid = sqlite3.connect('identity.db')
In [ ]:
connid
In [ ]:
c = connid.cursor()
In [ ]:
def createdb(nameofdb):
    connid = sqlite3.connect('{}.db'.format(nameofdb))
    c.execute('''CREATE TABLE truckspec
             (truckid, trucktype, emptyweight, maxgrossoperatingweight)''')

    c = connid.cursor()
    
    c.close()

    return(nameofdb)
In [ ]:
createdb('testing')
In [ ]:
 
In [ ]:
createdb('truckspec')
In [ ]:
 
In [ ]:
c.execute('''CREATE TABLE truckspec
             (truckid, trucktype, emptyweight, maxgrossoperatingweight)''')
In [ ]:
def createtruk(truckid, trucktype, emptyweight, maxgrossoperatingweight):
    connid = sqlite3.connect('truckspec.db')
    c = connid.cursor()
    c.execute("INSERT INTO truckspec VALUES ('{}','{}','{}', '{}')".format(truckid, trucktype, emptyweight, maxgrossoperatingweight))
    connid.commit()
    connid.close()

    return({truckid : dict({'trucktype' : trucktype, 'emptyweight' : emptyweight,
                           'maxgrossoperatingweight' : maxgrossoperatingweight})})
In [ ]:
def select_all_tasks():
    """
    Query all rows in the tasks table
    :param conn: the Connection object
    :return:
    """
    connid = sqlite3.connect('truckspec.db')

    cur = connid.cursor()
    cur.execute("SELECT * truckspec;")
 
    rows = cur.fetchall()
 
    for row in rows:
        print(row)
In [ ]:
select_all_tasks()
In [ ]:
 
In [ ]:
 
In [ ]:
createtruk(420, '789C', 124114, 317514.85)
In [ ]:
createtruk(421, '789C', 114114, 317514.85)
In [ ]:
cat /home/wcmckee/truckspec.json
In [ ]:
truk.to_json()
In [ ]:
truk.sort_values(by='Truck ID')

an api on truck spec

{401 : dict({'type' : '789c', 'emptyweight' : 124114, 'maxweight' : 317514.85})}

In [ ]:
forohon = ({401 : dict({'type' : '789c', 'emptyweight' : 124114, 'maxweight' : 317514.85})})
In [ ]:
forohon
In [ ]:
tru.loc[tru['Truck'] == 'TRH404']
In [ ]:
tulo = tru.loc('TRH404')
In [ ]:
tulo.name
In [ ]:
print(tulo())
In [ ]:
roadsegdata = {'Road-segment-data' : dict({'Truck' : 'ID of the 16 CAT trucks', 
                             'Description - CR' : 'Grade the truck needs to climb',
                            'Payload' : 'Weight in kg excluding truck weight.',
                            'Start velocity' : 'Force the truck starts the grade in km/hr.',
                            'End velocity' : 'Force the truck exits the grade in km/hr.',
                            'EfhLength' : 'Not valid as it is an old measure of distance.', 
                            'Target duration' : 'Optimal time for the truck to cover the grade in seconds.', 
                            'Duration calculated' : 'Actual time for the truck to cover the grade in seconds.',
                            'Slope length' : 'Slope length(curvature distance) in meters.',
                            'Rise height' : 'Measure of the slope in meters.',
                            'StartWayPoint X,Y,Z' : 'Starting location of the grade',
                            'EndWayPoint X,Y,Z' : 'Ending location of the grade.'})}
In [ ]:
print(roadsegdata)
In [ ]:
truckcycledict = {'Truck cycle' : dict({'Date' : 'Date the data was recorded.', 
                       'Source stage' : 'Stage the truck starts from.',
                      'Source bench' : 'Bench the truck starts from.',
                      'Destination name' : 'Unloading dump.', 
                      'Truck' : 'ID of the 16 CAT trucks',
                      'Travelling empty duration' : 'Travelling time in seconds when the truck is empty. (return time duration',
                      'Travelling full duration' : 'Travelling time in seconds when the truck is loaded.',
                      'Payload' : 'Weight in kg excluding truck weight.',
                      'Full slope length' : 'Distance in meters from bench to dump location.',
                      'Empty slope length' : 'Return distance in meters.',
                      'Inpit ramp length' : 'Distance from the bench to the exit of the pit in meters.', 
                     'Inpit ramp grade' : 'Inclination angle of the in-pit grade in %',
                      'Dump ramp length' : 'Distance from the exit of pit to the dump location.', 
                      'Dump ramp grade' : 'Inclination angle after the exit of pit to the dump location in %.'})}
In [ ]:
trucyc = truckcycledict['Truck cycle']
In [ ]:
print(trucyc)
In [ ]:
for truc in trucyc:
    print(truc)
In [ ]:
truckcycledict.update(roadsegdata)
In [ ]:
truckcy = json.dumps(truckcycledict)
In [ ]:
with open('/home/wcmckee/truckscycroad.json', 'w') as t:
    t.write(truckcy)
In [ ]:
 
In [159]:
with open('/home/wcmckee/truckscycroad.json', 'r') as r:
    #print(r.read())
    decjs = json.loads(r.read())
In [ ]:
print({410 : dict({'Truck' : 410, 'Payload' : 100, })})
In [160]:
print(decjs['Road-segment-data'])
{'Target duration': 'Optimal time for the truck to cover the grade in seconds.', 'Truck': 'ID of the 16 CAT trucks', 'End velocity': 'Force the truck exits the grade in km/hr.', 'Duration calculated': 'Actual time for the truck to cover the grade in seconds.', 'Payload': 'Weight in kg excluding truck weight.', 'StartWayPoint X,Y,Z': 'Starting location of the grade', 'Description - CR': 'Grade the truck needs to climb', 'Rise height': 'Measure of the slope in meters.', 'EndWayPoint X,Y,Z': 'Ending location of the grade.', 'Start velocity': 'Force the truck starts the grade in km/hr.', 'EfhLength': 'Not valid as it is an old measure of distance.', 'Slope length': 'Slope length(curvature distance) in meters.'}
In [161]:
print(decjs['Truck cycle'])
{'Travelling full duration': 'Travelling time in seconds when the truck is loaded.', 'Inpit ramp length': 'Distance from the bench to the exit of the pit in meters.', 'Truck': 'ID of the 16 CAT trucks', 'Destination name': 'Unloading dump.', 'Empty slope length': 'Return distance in meters.', 'Date': 'Date the data was recorded.', 'Dump ramp length': 'Distance from the exit of pit to the dump location.', 'Payload': 'Weight in kg excluding truck weight.', 'Full slope length': 'Distance in meters from bench to dump location.', 'Dump ramp grade': 'Inclination angle after the exit of pit to the dump location in %.', 'Inpit ramp grade': 'Inclination angle of the in-pit grade in %', 'Source bench': 'Bench the truck starts from.', 'Travelling empty duration': 'Travelling time in seconds when the truck is empty. (return time duration', 'Source stage': 'Stage the truck starts from.'}
In [ ]:
cat /home/wcmckee/truckscycroad.json
In [ ]:
for trucy in truckcycledict['Road-segment-data']:
    print({trucy : dict({'example' : 'l33t', 'Description' : 'this is an example'})})
    
    
In [ ]:
def createlocation(truck, longitude, latitude):
    return({'truck' : truck, 'longitude' : longitude, 'latitude' : latitude})
In [ ]:
import pandas
In [ ]:
descri = pandas.read_excel('/home/wcmckee/data/Road Segment Data.xlsx')
In [ ]:
dropcol = descri.drop('Unnamed: 0', axis=1)
In [ ]:
with open('/home/wcmckee/roadsegdatatest.json', 'w') as roaddrop:
    roaddrop.write(dropcol.to_json())
In [ ]:
with open('/home/wcmckee/roadsegdatatest.json', 'r') as roard:
    roadjsconv = roard.read()
In [ ]:
import json
In [ ]:
roadjslod = json.loads(roadjsconv)
In [ ]:
import getpass
In [ ]:
getpass.getuser()
In [ ]:
 
In [ ]:
for paka in roadjslod.keys():
    print(roadjslod[paka]['127'])
In [ ]:
startdict ={'StartWaypoint' : dict({'x' : int(samptru['StartWaypointCoordsX']), 
                         'y' : int(samptru['StartWaypointCoordsY']), 
                         'z' : int(samptru['StartWaypointCoordsZ']),
                        'velocity' : int(samptru['StartVelocity'])})}
In [ ]:
startdict
In [ ]:
def xyz(startx, starty, startz, startvelo, endx, endy, endz, endvelo):
           return({'startwaypoint' : dict({'x' : startx, 
                         'y' : starty, 
                         'z' : startz,
                        'velocity' : startvelo}),
                  'endwaypoint' : dict({'x' : endx, 'y' : endy, 'z' : endz, 
                                        'velocity' : endvelo})})
In [ ]:
xyz(86545, 36238, 1097, 13, 86578, 36354, 1097, 13)
In [ ]:
endist = {'EndWaypoint' : dict({'x' : int(samptru['EndWaypointCoordsX']), 
                       'y' : int(samptru['EndWaypointCoordsY']),
                      'z' : int(samptru['StartWaypointCoordsZ']),
                      'velocity' : int(samptru['EndVelocity'])})}
In [ ]:
startdict.update(endist)
In [ ]:
{'stats' : dict({'Description-CR' : samptru['Description-CR']})}
In [ ]:
samdes = samptru['Description-CR']
In [ ]:
import requests
In [ ]:
reqge = requests.get('https://geocode.xyz/51.50354,-0.12768')
In [ ]:
rejs = (reqge.json)
In [ ]:
print(str(rejs))
In [ ]:
print(dict({'truck' : truck, dict({'startwaypoint' : {'longitude' : int(samptru['StartWaypointCoordsX'], 'latitude' : int(samptru['StartWaypointCoordsY']))}}
In [ ]:
print ({'truck' : 402, dict({'startwaypoint' : dict({'longitude' : 1, 'latitude' : 3})})
In [ ]:
{'startwaypoint' : dict({'longitude' : 1, 'latitude' : 3})}
In [157]:
trukxlc = pandas.read_excel('/home/wcmckee/data/Scenario1.xlsx')
In [ ]:
 
In [158]:
print(trukxlc['Destination 1'])
0      Material Carried: 50%
1                          Y
2                    36277.7
3                      36284
4                    36262.6
5                    36256.8
6                    36239.5
7                    36228.9
8                    36214.3
9                    36206.9
10                   36203.7
11                   36202.4
12                   36203.7
13                   36216.5
14                   36230.2
15                   36255.4
16                   36271.1
17                   36287.6
18                   36369.5
19                   36399.5
20                   36418.2
21                   36445.7
22                   36441.9
23                   36431.9
24                   36375.1
25                   36331.4
26                   36291.2
27                     36224
28                   36195.9
29                   36176.6
               ...          
82                   36715.2
83                   36653.3
84                   36620.6
85                   36601.8
86                   36540.6
87                   36530.5
88                   36515.1
89                   36458.7
90                   36383.8
91                   36316.8
92                   36287.3
93                   36270.7
94                   36222.7
95                   36156.4
96                   36094.5
97                   36042.8
98                   35983.4
99                   35970.8
100                  35962.4
101                      NaN
102                      NaN
103                      NaN
104                      NaN
105                      NaN
106                      NaN
107                      NaN
108                      NaN
109                      NaN
110                      NaN
111                      NaN
Name: Destination 1, dtype: object
In [ ]:
trukcyc = pandas.read_csv('/home/wcmckee/data/Truck Cycle.csv', index_col='Truck')
In [ ]:
for trkey in trukcyc.keys():
    trk = (trkey.replace(' ', '-'))
    print(trk.lower())
In [ ]:
import json
In [ ]:
import random
In [ ]:
print(truckdicspec)
In [ ]:
with open('/home/wcmckee/truckspec.json', 'r') as truatm:
        tread = truatm.read()
        truckdicspec = json.loads(tread)
        truckid = random.choice(truckdicspec)
In [ ]:
truits = trukcyc.iteritems()
In [ ]:
somedict = dict()
In [ ]:
somedict
In [ ]:
somelis = list()
In [ ]:
 
In [ ]:
for tru in truits:
    #print(tru)
    somelis.append(tru)
    #somedict.update({tru : tru})
In [ ]:
for somel in somelis:
    print(somel)
In [ ]:
for somel in somelis:
    print(somel)
In [ ]:
import random
In [ ]:
random.choice()
In [ ]:
def createtruckcyc(date, sourcestage, sourcebench, destinationname,
       travellingemptyduration, travellingfullduration, payload,
       fullslopelength, emptyslopelength, inpitramplength,
       inpitrampgrade, dumpramplength, dumprampgrade):
        return (dict({'date' : date, 'sourcestage' : sourcebench, 'sourcebench' : sourcebench, 
                      'destinationname' : destinationname, 
                      'travellingemptyduration' : travellingemptyduration, 
                      'travellingfullduration' : travellingfullduration, 
                      'payload' : payload, 'fullslopelength' : fullslopelength, 
                      'emptyslopelength' : emptyslopelength, 
                      'inpitramplength' : inpitramplength, 
                      'inpitrampgrade' : inpitrampgrade, 'dumpramplength' : dumpramplength, 
                      'dumprampgrade' : dumprampgrade}))
In [ ]:
import arrow
In [ ]:
timnow = arrow.now()
In [ ]:
print(timnow)
In [ ]:
str(timnow.date())
In [ ]:
'9.34%', 336.00, '8.33%'
In [ ]:
createtruckcyc('01/01/2017', 'Stage G', '920', 'MW_PRIME', 0.0, 1009, 179.7, 3888.21, 3888.21,
              42.94, 3108.02, '9.34%', 336.00, '8.33%')
In [ ]:
trjs = trukcyc.to_json
In [ ]:
 
In [ ]:
 
In [ ]:
with open('/home/wcmckee/truckdetail.json', 'w') as truckdet:
    truckdet.write(trjs)
In [ ]:
trukd = pandas.read_json('/home/wcmckee/truckdetail.json')
In [ ]:
trukcyc.to_json 
In [ ]:
 
In [ ]:
trujsn = (trukcyc.to_json)
In [ ]:
trujsn
In [ ]:
trujsn
In [ ]:
with open('/home/wcmckee/truckinfo.json', 'w') as truwri:
    truwri.write(str(trujsn))
In [ ]:
 
In [ ]:
cat /home/wcmckee/truckinfo.json
In [ ]:
import arrow
In [ ]:
 
In [ ]:
def mkblogpost(blogpath, postname, tagblog):
    raw = arrow.now()
    fultim = raw.datetime
    
    if postname + '.md' not in os.listdir(blogpath + '/posts'):
        with open(blogpath + '/posts/' + postname + '.meta', 'w') as daympo:
            daympo.write('.. title: {}\n.. slug: {}\n.. date: {}\n.. tags: {}\n.. link:\n.. description:\n.. type: text'.format(postname, postname, fultim, tagblog))
            
        with open(blogpath + '/posts/' + postname + '.md', 'w') as daymark:
            for toar in os.listdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d')):

                daymark.write('![{}]({}{})\n\n'.format(toar.replace('.png', ''), '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d') + '/', toar))
In [ ]:
print(trukcyc['Destination name'])
In [ ]:
from flask import Flask, request, jsonify
import json

import getpass
myusr = getpass.getuser()
homepath = '/home/{}'.format(myusr)
app = Flask(__name__)
In [ ]:
with open('{}/truckspec.json'.format(homepath), 'r') as truatm:
    #opens the truck spec json file. 
    tread = truatm.read()
    
truckdicspec = json.loads(tread)

with open('{}/roadsegdatatest.json'.format(homepath), 'r') as roard:
    #opens the road seg data 
    roadjsconv = roard.read()
    
roadjslod = json.loads(roadjsconv)
      
In [ ]:
 
In [ ]:
@app.route('/getruckspec')
def getruckspec():
    # give it truck id and returns back stats about that truck.
    # todo: return back truck segment details also. 
    #localhost:5555/getruckspec?truckid=410
    #returns back:
    #{"EmptyWeight": 124114, "MaxOperatingWeight": 317514.85, "TruckType": "789C"}
    truckid = request.args.get('truckid')
    #truckid = request.args.get("truckid")
    
    return(jsonify({'EmptyWeight' : truckdicspec['EmptyWeight'][truckid],
        'MaxOperatingWeight' : truckdicspec['MaxOperatingWeight'][truckid], 'TruckType' : truckdicspec['TruckType'][truckid]}))
In [ ]:
@app.route('/getroadsegid')
def getroadsegid():
    #localhost:5555/getroadsegid?segid=95
    #give it id and return back road segiment details. 
    '''
    returns back: {
  "Description-CR": "GRD25-GRD26", 
  "DurationCalculated": 28.0, 
  "EfhLength": 157.9984208252, 
  "EndVelocity": 21.9239999982, 
  "EndWaypointCoordsX": 85976.84, 
  "EndWaypointCoordsY": 36378.8, 
  "EndWaypointCoordsZ_Q-CR": 885.02, 
  "LoadStateDirection_D-CR": "Reverse traversal full", 
  "Payload": 170900, 
  "RiseHeight": 0.15, 
  "SlopeLength": 148.8954144547, 
  "StartVelocity": 13.3919999989, 
  "StartWaypointCoordsX": 85987.63, 
  "StartWaypointCoordsY": 36257.25, 
  "StartWaypointCoordsZ": 885.05, 
  "TargetDuration": 11, 
  "Truck": "TRH405"
}
'''
    segid = request.args.get('segid')
    newdict = dict()

    for paka in roadjslod.keys():
        newdict.update({paka : roadjslod[paka][segid]})
    return(jsonify(newdict))
    #return('everything worked')


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5555) 
In [ ]:
from flask import Flask, request, jsonify
import json

import getpass
myusr = getpass.getuser()
homepath = '/home/{}'.format(myusr)
app = Flask(__name__)


with open('{}/truckspec.json'.format(homepath), 'r') as truatm:
    #opens the truck spec json file. 
    tread = truatm.read()
    
truckdicspec = json.loads(tread)

with open('{}/roadsegdatatest.json'.format(homepath), 'r') as roard:
    #opens the road seg data 
    roadjsconv = roard.read()
    
roadjslod = json.loads(roadjsconv)
      
@app.route('/getruckspec')
def getruckspec():
    # give it truck id and returns back stats about that truck.
    # todo: return back truck segment details also. 
    #localhost:5555/getruckspec?truckid=410
    #returns back:
    #{"EmptyWeight": 124114, "MaxOperatingWeight": 317514.85, "TruckType": "789C"}
    truckid = request.args.get('truckid')
    #truckid = request.args.get("truckid")
    
    return(jsonify({'EmptyWeight' : truckdicspec['EmptyWeight'][truckid],
        'MaxOperatingWeight' : truckdicspec['MaxOperatingWeight'][truckid], 'TruckType' : truckdicspec['TruckType'][truckid]}))

@app.route('/getroadsegid')
def getroadsegid():
    #localhost:5555/getroadsegid?segid=95
    #give it id and return back road segiment details. 
    '''
    returns back: {
  "Description-CR": "GRD25-GRD26", 
  "DurationCalculated": 28.0, 
  "EfhLength": 157.9984208252, 
  "EndVelocity": 21.9239999982, 
  "EndWaypointCoordsX": 85976.84, 
  "EndWaypointCoordsY": 36378.8, 
  "EndWaypointCoordsZ_Q-CR": 885.02, 
  "LoadStateDirection_D-CR": "Reverse traversal full", 
  "Payload": 170900, 
  "RiseHeight": 0.15, 
  "SlopeLength": 148.8954144547, 
  "StartVelocity": 13.3919999989, 
  "StartWaypointCoordsX": 85987.63, 
  "StartWaypointCoordsY": 36257.25, 
  "StartWaypointCoordsZ": 885.05, 
  "TargetDuration": 11, 
  "Truck": "TRH405"
}
'''
    segid = request.args.get('segid')
    newdict = dict()

    for paka in roadjslod.keys():
        newdict.update({paka : roadjslod[paka][segid]})
    return(jsonify(newdict))
    #return('everything worked')


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5555) 

Comments

Comments powered by Disqus