Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions website/scriptFactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#Generic for script.cel file
script = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

эти массив строк нигде не используется кроме как в методе makeScript - поэтому нет смысла выносить его отдельно. Можно сразу писать в самом методе, тогда получится примерно следующее:
+def makeScript(beginDate,shipName):
script = [
{\n',

  • time{utc "' + str(beginDate) + '"}\n',
  • 'select{object "' + str(shipName) + '"}\n',
  • 'center {time 5.0}\n',
  • 'goto { time 5.0 }\n',
  • 'follow{}\n',
  • 'lock{}\n',
    +'}'
    ]
    .....

Плюс нужно проверять что параметры метода не пустые и валидные

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Валидацию завтра реализую.
По поводу решения вынести шаблон скрипта в глобальное поле:
дефолтные скрипты могут часто использоваться, достать без генерации можно будет как scriptFactory.script

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему они будут часто использоваться?

Что мне не нравится в script - это явно прописанное время. Сейчас там прописана дата, пусть условно она актуальна сейчас(хотя там 2015 год...), но, например. пройдет еще год - хотим мы по дефолту иметь там 2015? На мой взгляд, если нам реально нужно возвращать по дефолту что-то, то хочется там видеть время с 1 января текущего года.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет ли в питоне каких то средств работы с временем? что нибудь типа DateTime.UTCNow()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да, есть.
январь 2015 это то, начиная откуда по дефолту генерится траектория. Поэтому и скрипт дефолтный такой.
В питоне есть именные параметры метода, можем сделать, что если begind/endDate не заданы, берём текущую дату. шаблон скрипта соответственно будет внутри метода.
полиморфизм соответственно будет в том, что если вызываем метод без параметров, будет возвращаться дефолтный скрипт с текущей датой.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тогда ещё вопрос с датой окончания
можно захардкодить например +1 год...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да хорошо, можно даже не текущую дату, а начало текущего года, ну и конец года как дату окончания - по дефолту 1 год для околоземных орбит нормально мне кажется.

'{\n',
'time{utc "2015-01-01T00:01:24.0000"}\n',
'select{object "Orbit-test-spacecraft"}\n',
'center {time 5.0}\n',
'goto { time 5.0 }\n',
'follow{}\n',
'lock{}\n',
'}'
]

#Generic for orbit.ssc file
scriptSSC = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тот же коммент что и для makeScript и script

'"Orbit-test-spacecraft" "Sol"\n',
'{\n',
'\tClass "spacecraft"\n',
'\tMesh "orbit.3ds"\n',
'\tRadius 0.011\n',
'\tOrientation [ 180 1 0 0 ]\n',
'\tTimeline [\n',
'\t# Phase 3: Solstice mission\n',
'\t{\n',
'\tBeginning "2015 01 01 00:00:00"\n',
'\tEnding "2020 9 15 17:02:00"\n',
'\tOrbitFrame { EclipticJ2000 { Center "Sol/Earth" } }\n',
'\tSampledTrajectory { Source "orbit.xyzv" }\n',
'\t}\n',
'\t]\n',
'}\n',
]


def makeScript(beginDate,shipName):
#set new begin date
script[1] = 'time{utc "' + str(beginDate) + '"}\n'
#set new ship object
script[2] = 'select{object "' + str(shipName) + '"}\n'

f = open("script.cel","w")
for line in script:
f.write(line)

def makeSSCScript(beginDate, endDate, shipName):
#set new ship name
scriptSSC[0] = '"'+str(shipName)+'" "Sol"\n'
#set new begin/end date
scriptSSC[9] = '\tBeginning "' +str(beginDate)+'"\n'
scriptSSC[10] = '\tEnding "' +str(endDate)+'"\n'

f = open("orbit.ssc","w")
for line in scriptSSC:
f.write(line)

if __name__ == '__main__':
makeScript("2015 01 01 00:00:00","ORBIT")
makeSSCScript("2015 01 01 00:00:00","2016 01 01 00:00:00","ORBIT")