如何解决用数组填写时间表
我正在制作一个时间表来自动生成一些东西,比如你会从学校知道的时间表。我很擅长让它填满我的表格,但我不确定针对这个确切目的的最佳实践会是什么样子。
我在上面的图片中添加了单元格编号,以表明我的观点。我想要做的是使“会话 2”行以“偏移量”为 1 运行循环,因此在单元格 5、10 中,15 和 20 将是“Lars”。
这是我现在的代码
$par_student = [
'Jennifer','John','Jane','Lars'
];
$sess_count = 0;
// for each row
for ($i = 0; $i <= $count_intervals; $i++) {
// here is the loop that generates the session number and date/time,not relevant for my question.
// below,is where I go through the array of students.
for ($r = 1; $r <= $count_rooms; $r++) {
$index = $r - $i - 1;
$sess_count++;
if ($index >= 0) :
echo $par_student[$index];
endif;
}
如您所见,现在,我每次都跳过索引以进行计数,但是当循环下降到单元格 5 时,我卡住了,似乎无法找出正确的方法来执行此操作.
我希望我的问题有意义。谢谢!
解决方法
您可以使用以下方式
readable_files = (
pipeline
| fileio.MatchFiles('hdfs://path/to/*.txt')
| fileio.ReadMatches()
| beam.Reshuffle())
files_and_contents = (
readable_files
| beam.Map(lambda x: (x.metadata.path,x.read_utf8())))
序列将是 Jennifer > John > Jane > Lars
但是当您从会话 1 分配到会话 8 时
Room A Room B Room C Room D
session 1 Jennifer John Jane Lars
session 2 John Jane Lars Jennifer
session 3 Jane Lars Jennifer John
session 4 Lars Jennifer John Jane
所以现在你可以使用上面的偏移量来调整你的 for 循环,我建议你使用 1,2,3,4,5,6,7,8 为 Room 1 ,并说 9,10,11,12,2号房13、14、15、16号(而不是1号房、2号房、3号房、4号房分别是1、2、3、4号)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。